Skip to content

Commit

Permalink
Basic demo
Browse files Browse the repository at this point in the history
  • Loading branch information
PrafulB committed Apr 3, 2024
1 parent 6df99d7 commit 1812c9d
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions testYjs.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,14 @@
import("https://esm.sh/[email protected]").then(async yjs => {

const ydoc = new yjs.Doc()

let yarray = ydoc.getArray("numbers");

yarray.insert(0, [1234]);
yarray.insert(0, [5, 6]);

const updates = yjs.encodeStateAsUpdate(ydoc);
console.log(yjs.decodeUpdate(updates));


const yarrayShared = ydoc.getArray('c4bNumbers')

const yjsWebRTC = await import("https://esm.sh/[email protected]")

const provider = new yjsWebRTC.WebrtcProvider("c4b", ydoc, {
signaling: ["wss://violet-peas-pay.loca.lt"]
})

yarrayShared = ydoc.getArray('c4bNumbers')

provider.on('synced', synced => {
console.log('synced!', synced)
})

yarrayShared.observeDeep(() => {
console.log("yarray updated: ", yarrayShared.toJSON());
})
})
const updateYArrayShared = (value) => {
yarrayShared.insert(0, value)
Expand Down

0 comments on commit 1812c9d

Please sign in to comment.