Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observe is not recursive? #43

Closed
davidbrochart opened this issue Apr 25, 2022 · 1 comment · Fixed by #47
Closed

Observe is not recursive? #43

davidbrochart opened this issue Apr 25, 2022 · 1 comment · Fixed by #47
Assignees

Comments

@davidbrochart
Copy link
Collaborator

Consider the following code, where ydoc has a YMap, which has a YArray in "array":

import y_py as Y

ydoc = Y.YDoc()
ymap = ydoc.get_map("map")
yarray = Y.YArray()

with ydoc.begin_transaction() as t:
    ymap.set(t, "array", yarray)

def callback(event):
    print(event.target)

ymap.observe(callback)
print("Changes:")
with ydoc.begin_transaction() as t:
    ymap["array"].push(t, [0])

ymap["array"].observe(callback)
print("Changes:")
with ydoc.begin_transaction() as t:
    ymap["array"].push(t, [1])

The output is:

Changes:
Changes:
[0.0, 1.0]

Meaning that observing only the top-level YMap doesn't trigger the callback if the YArray is changed.
I think we should have an option to enable that, e.g. ymap.observe(callback, recursive=True). What do you think?

@Horusiath
Copy link

In yrs there's a method called observe_deep/unobserve_deep, but I think it's not yet exposed in Ypy.

@Waidhoferj Waidhoferj self-assigned this Apr 28, 2022
@Waidhoferj Waidhoferj mentioned this issue Apr 28, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants