{"id":15316407,"url":"https://github.com/joebobmiles/yjson","last_synced_at":"2025-04-15T02:21:17.888Z","repository":{"id":48872599,"uuid":"383224123","full_name":"joebobmiles/yjson","owner":"joebobmiles","description":"Yjs backed Plain Data Objects.","archived":false,"fork":false,"pushed_at":"2021-07-07T16:51:51.000Z","size":493,"stargazers_count":13,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T14:11:08.484Z","etag":null,"topics":["collaboration","crdt","distributed-storage","json","local-first","offline-first","p2p","pdo","peer-to-peer","yjs","yjs-bindings"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joebobmiles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-05T17:55:19.000Z","updated_at":"2024-07-16T08:17:46.000Z","dependencies_parsed_at":"2022-09-02T09:22:37.580Z","dependency_job_id":null,"html_url":"https://github.com/joebobmiles/yjson","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joebobmiles%2Fyjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joebobmiles%2Fyjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joebobmiles%2Fyjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joebobmiles%2Fyjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joebobmiles","download_url":"https://codeload.github.com/joebobmiles/yjson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991714,"owners_count":21194926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collaboration","crdt","distributed-storage","json","local-first","offline-first","p2p","pdo","peer-to-peer","yjs","yjs-bindings"],"created_at":"2024-10-01T08:54:02.346Z","updated_at":"2025-04-15T02:21:17.869Z","avatar_url":"https://github.com/joebobmiles.png","language":"JavaScript","readme":"# YJSON\n\n[Yjs](https://github.com/yjs/yjs) is a brilliant JavaScript library for using\n[Conflict-Free Replicated Data Types (CRDTs)](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type)\nin the browser. *YJSON* wraps that library to make using Yjs as simple as\nworking with Plain Data Objects.\n\n## Why?\n\nYjs's base API is nice and simple, but it is difficult to use when building\nlibraries with modern state-management paradigms, such as Redux, Mobx, or\nZustand. Looking for state-management frameworks that were built on Yjs, I found\nthat there were very few, particularly in the React space.\n\nAfter trying to create a Redux clone backed by Yjs, I had learned why. What\nwould simplify things is to treat the store as a Yjs Map that contained other\nshared types. This map would then be manipulated as a plain JSON object by the\nstate logic.\n\nThus, YJSON.\n\n## What?\n\nYJSON provides a function, `yjson` that accepts a Yjs Document and returns an\nempty JSON object. This object is a 'store' whose contents are synced in the\nbackground by Yjs. You don't need to worry about transforming back and forth\nbetween shared types, as YJSON objects do that automatically, effectively hiding\nthat Yjs is involved at all.\n\n## Example\n\n```js\nconst Y = require(\"yjs\");\nconst yjson = require(\"yjson\").default;\n\n// Create two new documents.\nconst doc1 = new Y.Doc();\nconst doc2 = new Y.Doc();\n\n// When doc1 updates, apply the update to doc2.\ndoc1.on(\"update\", (update) =\u003e\n{\n    Y.applyUpdate(doc2, update);\n});\n// Vice-versa\ndoc2.on(\"update\", (update) =\u003e\n{\n    Y.applyUpdate(doc1, update);\n});\n\n// Create a YJSON object from each document.\nconst storeA = yjson(doc1, \"shared\");\nconst storeB = yjson(doc2, \"shared\");\n\n// Add a key \"foo\" with value \"bar\" to storeA.\nstoreA.foo = \"bar\";\n\n// Print the contents of storeB\nconsole.log(storeB) // =\u003e { foo: \"bar\" }\n```\n\n## Caveats\n\n 1. Yjs Text shared types are not supported. In the future, any string you put\n    in a YJSON object will be transformed into Yjs Text instances.\n 1. YJSON objects currently provide no system for subscribing or observing\n    updates. This will be implemented in the future to allow for interaction\n    with functional reactive systems like React.\n\n---\n\n## License\n\nThis library is licensed under the MIT License.\n\n\u003e Copyright (c) 2021 Joseph R Miles \u003cjoe@jrm.dev\u003e\n\u003e \n\u003e Permission is hereby granted, free of charge, to any person obtaining a copy of\n\u003e this software and associated documentation files (the \"Software\"), to deal in\n\u003e the Software without restriction, including without limitation the rights to\n\u003e use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n\u003e the Software, and to permit persons to whom the Software is furnished to do so,\n\u003e subject to the following conditions:\n\u003e \n\u003e The above copyright notice and this permission notice shall be included in all\n\u003e copies or substantial portions of the Software.\n\u003e \n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\u003e IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n\u003e FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n\u003e COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n\u003e IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n\u003e CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoebobmiles%2Fyjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoebobmiles%2Fyjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoebobmiles%2Fyjson/lists"}