From aaa6d1fa54b042a7ba03757e5d88aa5702bda32c Mon Sep 17 00:00:00 2001 From: ChrisLincoln Date: Fri, 15 May 2020 14:16:28 -0500 Subject: [PATCH] =?UTF-8?q?Changed=20the=20backend=20socket=20config=20typ?= =?UTF-8?q?es=20fom=20Element[]=20to=20Node[]=20and=20m=E2=80=A6=20(#14)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Changed the backend socket config types fom Element[] to Node[] and made the onDocumentLoad async * Updated onDocumentLoad in readme --- README.md | 2 +- packages/backend/src/AutomergeBackend.ts | 4 ++-- packages/backend/src/SocketIOConnection.ts | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d2cfd64..367f03e 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ const connection = new SocketIOConnection(options) onDocumentLoad: ( // request slate document callback pathname: string, query?: Object - ) => Node[] + ) => Promise | Node[] onDocumentSave: (pathname: string, doc: Node[]) => Promise | void // save document callback } ``` diff --git a/packages/backend/src/AutomergeBackend.ts b/packages/backend/src/AutomergeBackend.ts index 5a30075..5302c29 100644 --- a/packages/backend/src/AutomergeBackend.ts +++ b/packages/backend/src/AutomergeBackend.ts @@ -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}`) diff --git a/packages/backend/src/SocketIOConnection.ts b/packages/backend/src/SocketIOConnection.ts index 3856406..c7171a3 100644 --- a/packages/backend/src/SocketIOConnection.ts +++ b/packages/backend/src/SocketIOConnection.ts @@ -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 - onDocumentLoad?: (pathname: string, query?: Object) => Element[] - onDocumentSave?: (pathname: string, doc: Element[]) => Promise | void + onDocumentLoad?: ( + pathname: string, + query?: Object + ) => Promise | Node[] + onDocumentSave?: (pathname: string, doc: Node[]) => Promise | void } export default class SocketIOCollaboration {