y-crdt/ypy

`to_json()` generates updates

davidbrochart opened this issue · 4 comments

The following example shows that calling to_json() actually generates an update:

import y_py as Y

ydoc = Y.YDoc()
a = ydoc.get_array("a")

def cb(event):
    print("update:", event.get_update())

ydoc.observe_after_transaction(cb)
print("a =", a.to_json())

# update: b'\x00\x00'
# a = []

For a notebook document, it can generate quite a lot of them.
I am surprised that it happens for an action that doesn't modify the document. Is it expected? What do these updates correspond to?

cc @ellisonbg

Hmm, that is a good mystery...

@dmonad any idea?

chwzr commented

Calling Y.encode_state_vector() is also producing empty updates:

import y_py as Y

ydoc = Y.YDoc()

def cb(event):
    print("update:", event.get_update())

ydoc.observe_after_transaction(cb)

state = Y.encode_state_vector(ydoc)

will print:

update: b'\x00\x00'