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
This commit is contained in:
ChrisLincoln
2020-05-15 14:16:28 -05:00
committed by GitHub
parent 2a6d99c171
commit aaa6d1fa54
3 changed files with 10 additions and 7 deletions

View File

@@ -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}`)

View File

@@ -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 {