valtiojs / valtio-yjs

valtio-yjs makes yjs state easy
MIT License
270 stars 15 forks source link

Allow variable transactionOrigin value #18

Closed fson closed 2 years ago

fson commented 2 years ago

We needed transactionOrigin to be variable per transaction so that we can include a transaction ID in it (used to selectively apply updates from different sources).

This PR changes the transactionOrigin option to be a function that's called to get the value used as origin for each transaction.

I could have made this change in a backwards compatible way by allowing the option to be either the origin itself or the function returning it, but I opted to change the API instead, because having this kind of arguments is often a source of accidental complexity in libraries that accept a number of options. Additionally, allowing both values and functions could have had unexpected results, if you try to set the origin to be a function (e.g. a constructor, something I've seen used in the YJS codebase).

codesandbox-ci[bot] commented 2 years ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bef04bc386216505c0f1fc8815dafc7398d5e2a6:

Sandbox Source
React Configuration
React Typescript Configuration