Socket
Socket
Sign inDemoInstall

mobyjs

Package Overview
Dependencies
25
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mobyjs

Experimental bridge between MobX and Yjs. [Demo + Playground on CodeSandbox](https://codesandbox.io/s/moby-demo-yn42g?file=/src/App.tsx).


Version published
Weekly downloads
5
increased by66.67%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

MobY: MobX bindings for Yjs

Experimental bridge between MobX and Yjs. Demo + Playground on CodeSandbox.

What does this solve?

Although Yjs is great for data syncing, observing changes to your data model can be quite cumbersome. You'd need to manually call observe to keep updated of (incoming) changes and keep the rest of your application in sync.

MobY brings the reactive data model of MobX to Yjs. Combine best of both worlds:

  • Yjs: great for data syncing
  • MobX: great for developing applications that automatically react to state changes

Cool, how does it work?

Set up your yJS document (same as plain-yJS):

const ydoc = new Y.Doc();
const provider = new WebrtcProvider("doc", ydoc);

Call observeYJS to patch the document. From now on, ydoc will be compatible with MobX observers:

observeYJS(ydoc);

Use the Yjs document somewhere in an observer, for example using MobX autorun:

autorun(() => {
    console.log(ydoc.getMap("data").get("magicnumber")); // automatically log the Yjs value once it's updated
})

Or use mobx-react-lite to automatically rerender your React components.

Demo?

Playground on CodeSandbox. Open multiple windows and click the button to see the magic.

FAQs

Last updated on 14 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc