Skip to content

Commit

Permalink
feat: synchronize slate value on creation
Browse files Browse the repository at this point in the history
Syncronizes the editors value on creation by overwriting it with the current sharedType value

BREAKING CHANGE: Editor creation will now overwrite the slate value
  • Loading branch information
BitPhinix committed Jan 16, 2021
1 parent b575112 commit d5fda54
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 545 deletions.
38 changes: 5 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,12 @@ You might also want to take a look at ["CRDTs are the future"](https://josephg.c
Adding a 2-way binding from the editor to a Yjs document is as easy as:

```ts
import { withYjs } from 'slate-yjs';
import { withYjs, SyncElement } from 'slate-yjs';
import * as Y from 'yjs';

const yjsEditor = withYjs(editor);

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

## WebsocketEditor

Slate Yjs comes with built in support for [y-websocket](https://github.com/yjs/y-websocket):

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

const collabEditor = withWebsocket(yjsEditor, options);

// Connect editor
collabEditor.connect();
```

### Options

```ts
{
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
}
const doc = new Y.Doc();
const sharedType = doc.getArray<SyncElement>('content');
const yjsEditor = withYjs(editor, sharedType);
```

## Example project
Expand Down
Loading

0 comments on commit d5fda54

Please sign in to comment.