From d2daa58db221ada2c2ab98e8bfc48f9e2726c9fc Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Wed, 31 Jul 2019 18:44:59 +0200 Subject: [PATCH] typing --- package.json | 6 ++++++ src/y-websocket.js | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8ff73ce..b2fd0ca 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,12 @@ "url": "https://github.com/y-js/y-websocket/issues" }, "homepage": "https://github.com/y-js/y-websocket#readme", + "standard": { + "ignore": [ + "/dist", + "/node_modules" + ] + }, "dependencies": { "y-protocols": "0.0.6", "lib0": "0.0.5" diff --git a/src/y-websocket.js b/src/y-websocket.js index 10fda74..d068154 100644 --- a/src/y-websocket.js +++ b/src/y-websocket.js @@ -43,12 +43,10 @@ export class WebsocketProvider extends Observable { * @param {string} url * @param {string} roomname * @param {Y.Doc} doc + * @param {{awareness:awarenessProtocol.Awareness,db:any|null}} conf */ - constructor (url, roomname, doc, awareness = new awarenessProtocol.Awareness(doc)) { + constructor (url, roomname, doc, { awareness = new awarenessProtocol.Awareness(doc), db = null } = /** @type {any} */ ({})) { super() - window.addEventListener('beforeunload', () => { - awarenessProtocol.removeAwarenessStates(this.awareness, [this.doc.clientID], null) - }) // ensure that url is always ends with / while (url[url.length - 1] === '/') { url = url.slice(0, url.length - 1) @@ -60,6 +58,7 @@ export class WebsocketProvider extends Observable { * @type {Object} */ this._localAwarenessState = {} + this.db = db this.awareness = awareness this.wsconnected = false this.mux = mutex.createMutex() @@ -119,6 +118,9 @@ export class WebsocketProvider extends Observable { }) } } + window.addEventListener('beforeunload', () => { + awarenessProtocol.removeAwarenessStates(awareness, [this.doc.clientID], null) + }) awareness.on('change', this._awarenessUpdateHandler) this.connect() }