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

Pythonic API #141

Open
davidbrochart opened this issue Sep 21, 2023 · 0 comments
Open

Pythonic API #141

davidbrochart opened this issue Sep 21, 2023 · 0 comments

Comments

@davidbrochart
Copy link
Collaborator

Currently the API for the Y data structures (YText, YArray, YMap) differs from the API for the equivalent Python structures (str, list, dict, respectively).
For instance:

Ypy Python
ytext.extend(txn, "foo") text += "foo"
yarray.insert_range(txn, 3, [5, 2]) l =l[:3] + [5, 2] + l[3:]
ymap.set(txn, "key", "value") d["key"] = "value"

It seems to me that this is because the transaction object txn has to be passed around, and so I'm wondering if it has to be?
A transaction is tied to a document, and so are the root types. For instance in the following code:

doc = Y.YDoc()
ytext = doc.get_text("my_text")

with doc.begin_transaction() as txn:
    ytext.extend(txn, "foo")

ytext is a text root type of doc, and txn is the current transaction of doc. If txn were stored in doc, then ytext could have access to it, and there would be no need to pass it around, like so:

with doc.begin_transaction():  # stores txn in doc
    ytext.extend("foo")  # ytext, which is tied to doc, can access txn
    # then this becomes possible:
    # ytext += "foo"

I started experimenting with this idea in pycrdt, but maybe I'm missing something that will make this approach not viable.
Any feedback?

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

No branches or pull requests

1 participant