Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: yjs/y-websocket
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: yjs/y-websocket
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.1
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Mar 25, 2024

  1. add initializer to server/utils

    dmonad committed Mar 25, 2024

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    fc82264 View commit details
  2. fix lint issue

    dmonad committed Mar 25, 2024
    Copy the full SHA
    d4e0f46 View commit details
  3. 2.0.1

    dmonad committed Mar 25, 2024
    Copy the full SHA
    d4c951a View commit details
Showing with 21 additions and 5 deletions.
  1. +18 −2 bin/utils.cjs
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
20 changes: 18 additions & 2 deletions bin/utils.cjs
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ if (typeof persistenceDir === 'string') {
ldb.storeUpdate(docName, update)
})
},
writeState: async (docName, ydoc) => {}
writeState: async (_docName, _ydoc) => {}
}
}

@@ -85,7 +85,22 @@ const updateHandler = (update, _origin, doc, _tr) => {
doc.conns.forEach((_, conn) => send(doc, conn, message))
}

class WSSharedDoc extends Y.Doc {
/**
* @type {(ydoc: Y.Doc) => Promise<void>}
*/
let contentInitializor = _ydoc => Promise.resolve()

/**
* This function is called once every time a Yjs document is created. You can
* use it to pull data from an external source or initialize content.
*
* @param {(ydoc: Y.Doc) => Promise<void>} f
*/
export const setContentInitializor = (f) => {
contentInitializor = f
}

export class WSSharedDoc extends Y.Doc {
/**
* @param {string} name
*/
@@ -133,6 +148,7 @@ class WSSharedDoc extends Y.Doc {
{ maxWait: CALLBACK_DEBOUNCE_MAXWAIT }
))
}
this.whenInitialized = contentInitializor(this)
}
}

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "y-websocket",
"version": "2.0.0",
"version": "2.0.1",
"description": "Websockets provider for Yjs",
"main": "./dist/y-websocket.cjs",
"module": "./src/y-websocket.js",