Skip to content

Commit

Permalink
testing yjs
Browse files Browse the repository at this point in the history
  • Loading branch information
PrafulB committed Apr 3, 2024
1 parent f8343fc commit b991575
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions testYjs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body></body>
<script>
let yarrayShared;
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 yjsWebRTC = await import("https://esm.sh/[email protected]")

const provider = new yjsWebRTC.WebrtcProvider("c4b", ydoc, {
signaling: ["ws://localhost:4444"]
})

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)
}
</script>
</html>

0 comments on commit b991575

Please sign in to comment.