Changed the backend socket config types fom Element[] to Node[] and m… (#14)

* Changed the backend socket config types fom Element[] to Node[] and made the onDocumentLoad async

* Updated onDocumentLoad in readme
pull/15/head
ChrisLincoln 4 years ago committed by GitHub
parent 2a6d99c171
commit aaa6d1fa54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,7 +63,7 @@ const connection = new SocketIOConnection(options)
onDocumentLoad: ( // request slate document callback
pathname: string,
query?: Object
) => Node[]
) => Promise<Node[]> | Node[]
onDocumentSave: (pathname: string, doc: Node[]) => Promise<void> | void // save document callback
}
```

@ -1,6 +1,6 @@
import * as Automerge from 'automerge'
import { Element } from 'slate'
import { Node } from 'slate'
import {
toCollabAction,
@ -79,7 +79,7 @@ class AutomergeBackend {
* Append document to Automerge DocSet
*/
appendDocument = (docId: string, data: Element[]) => {
appendDocument = (docId: string, data: Node[]) => {
try {
if (this.getDocument(docId)) {
throw new Error(`Already has document with id: ${docId}`)

@ -1,6 +1,6 @@
import io from 'socket.io'
import * as Automerge from 'automerge'
import { Element } from 'slate'
import { Node } from 'slate'
import { Server } from 'http'
import throttle from 'lodash/throttle'
@ -14,14 +14,17 @@ import AutomergeBackend from './AutomergeBackend'
export interface SocketIOCollaborationOptions {
entry: number | Server
connectOpts?: SocketIO.ServerOptions
defaultValue?: Element[]
defaultValue?: Node[]
saveFrequency?: number
onAuthRequest?: (
query: Object,
socket?: SocketIO.Socket
) => Promise<boolean> | boolean
onDocumentLoad?: (pathname: string, query?: Object) => Element[]
onDocumentSave?: (pathname: string, doc: Element[]) => Promise<void> | void
onDocumentLoad?: (
pathname: string,
query?: Object
) => Promise<Node[]> | Node[]
onDocumentSave?: (pathname: string, doc: Node[]) => Promise<void> | void
}
export default class SocketIOCollaboration {

Loading…
Cancel
Save