Skip to content

Commit af9a1be

Browse files
committed
-
1 parent 91b2f56 commit af9a1be

File tree

2 files changed

+8
-38
lines changed

2 files changed

+8
-38
lines changed

tests/test_pycrdt_yjs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def callback(_event):
9393

9494
output_text.observe(callback)
9595

96-
with move_on_after(20):
96+
with move_on_after(10):
9797
await event.wait()
9898

9999
assert output_text.to_py() == ["Hello,", " World!"]

tests/yjs_client_1.js

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,16 @@ import { WebsocketProvider } from 'y-websocket'
88
import ws from 'ws'
99

1010
const notebook = new YNotebook()
11-
const cells = notebook.ydoc.getArray('cells')
12-
13-
function append_text() {
14-
const cell = notebook.getCell(0)
15-
const youtput = cell.youtputs.get(0)
16-
const text = youtput.get('text')
17-
text.insert(1, [' World!'])
18-
}
19-
20-
function callback2(event) {
21-
if (event.transaction.local) {
22-
return
23-
}
24-
25-
const cell = notebook.getCell(0)
26-
if (cell.youtputs.length > 0) {
27-
setTimeout(append_text, 100)
28-
}
29-
}
30-
31-
function callback1(event) {
32-
if (event.transaction.local) {
33-
return
34-
}
35-
36-
if (cells.length > 0) {
37-
const cell = notebook.getCell(0)
38-
if (cell.youtputs.length > 0) {
39-
setTimeout(append_text, 100)
40-
}
41-
else {
42-
cell.youtputs.observe(callback2)
43-
}
44-
}
45-
}
46-
47-
cells.observe(callback1)
4811

4912
const wsProvider = new WebsocketProvider(
5013
'ws://localhost:1234', 'my-roomname',
5114
notebook.ydoc,
5215
{ WebSocketPolyfill: ws }
5316
)
17+
18+
wsProvider.on('sync', (isSynced) => {
19+
const cell = notebook.getCell(0)
20+
const youtput = cell.youtputs.get(0)
21+
const text = youtput.get('text')
22+
text.insert(1, [' World!'])
23+
})

0 commit comments

Comments
 (0)