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 onDocumentLoad: ( // request slate document callback
pathname: string, pathname: string,
query?: Object query?: Object
) => Node[] ) => Promise<Node[]> | Node[]
onDocumentSave: (pathname: string, doc: Node[]) => Promise<void> | void // save document callback onDocumentSave: (pathname: string, doc: Node[]) => Promise<void> | void // save document callback
} }
``` ```

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

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

Loading…
Cancel
Save