npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yjson

v1.0.0-staging.1

Published

Yjs backed Plain Data Objects.

Downloads

4

Readme

YJSON

Yjs is a brilliant JavaScript library for using Conflict-Free Replicated Data Types (CRDTs) in the browser. YJSON wraps that library to make using Yjs as simple as working with Plain Data Objects.

Why?

Yjs's base API is nice and simple, but it is difficult to use when building libraries with modern state-management paradigms, such as Redux, Mobx, or Zustand. Looking for state-management frameworks that were built on Yjs, I found that there were very few, particularly in the React space.

After trying to create a Redux clone backed by Yjs, I had learned why. What would simplify things is to treat the store as a Yjs Map that contained other shared types. This map would then be manipulated as a plain JSON object by the state logic.

Thus, YJSON.

What?

YJSON provides a function, yjson that accepts a Yjs Document and returns an empty JSON object. This object is a 'store' whose contents are synced in the background by Yjs. You don't need to worry about transforming back and forth between shared types, as YJSON objects do that automatically, effectively hiding that Yjs is involved at all.

Example

const Y = require("yjs");
const yjson = require("yjson").default;

// Create two new documents.
const doc1 = new Y.Doc();
const doc2 = new Y.Doc();

// When doc1 updates, apply the update to doc2.
doc1.on("update", (update) =>
{
    Y.applyUpdate(doc2, update);
});
// Vice-versa
doc2.on("update", (update) =>
{
    Y.applyUpdate(doc1, update);
});

// Create a YJSON object from each document.
const storeA = yjson(doc1, "shared");
const storeB = yjson(doc2, "shared");

// Add a key "foo" with value "bar" to storeA.
storeA.foo = "bar";

// Print the contents of storeB
console.log(storeB) // => { foo: "bar" }

Caveats

  1. Yjs Text shared types are not supported. In the future, any string you put in a YJSON object will be transformed into Yjs Text instances.
  2. YJSON objects currently provide no system for subscribing or observing updates. This will be implemented in the future to allow for interaction with functional reactive systems like React.

License

This library is licensed under the MIT License.

Copyright (c) 2021 Joseph R Miles [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.