Git Product home page Git Product logo

slate-yjs's Introduction

Slate Yjs

(Experimental) Yjs bindings for Slate.

Heavily inspired by slate-collaboritve

Installation

Via npm:

npm install slate-yjs

Via yarn:

yarn add slate-yjs

Why use Slate Yjs instead of slate-collaborative?

Performance. slate-collaborative works well for small documents but causes 20 seconds plus load times on larger documents which slate-yjs can load in a fraction of a second.

For a more in-depth comparison take a look at this benchmark.

Why CRDTs over OT?

The article "CRDTs are the future" from the creator of sharedb might be interesting for you.

API

YjsEditor

Adding a 2-way binding from the editor to a yjs document is as easy as:

import { withYjs } from 'slate-yjs';

const yjsEditor = withYjs(editor);

// The 2-way bound sync doc
console.log(yjsEditor.syncDoc);

WebsocketEditor

Slate Yjs comes with built in support for y-websocket:

import { WebsocketEditorOptions, withWebsocket } from 'slate-yjs';

const collabEditor = withWebsocket(yjsEditor, options);

// Connect editor
collabEditor.connect();

Options

{
  roomName: string // Room name
  endpoint: string // Websocket endpoint
  onConnect?: () => void // Connect callback
  onDisconnect?: () => void // Disconnect callback
  connect?: boolean // Whether to connect automatically (default false)
  awareness?: awarenessProtocol.Awareness // Awareness protocol to use
  WebSocketPolyfill?: typeof WebSocket // Websocket polyfill to use
  resyncInterval?: number // Request server state every `resyncInterval` milliseconds
}

Example project

Take a look at the example project here

Contribute

Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

slate-yjs's People

Contributors

renovate[bot] avatar kjohnson-hugo avatar bitphinix avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.