Skip to content

[Question] Set method #3

Description

@thefooly

Hello!

I will briefly explain my problem:

In my use-case scenario I am sharing arrays among clients, unfortunately on each client I have to keep two copies of the same array: a "local" array created by another framework and your "y-array" used to share it. I can't get rid of the local array because it is not directly accessible, and I need your y-array to ensure consistency among clients.

The framework I am using notifies me with "update", "splice", "splices", etc. events whenever the "local" array changes, and I can change the "local" array by using methods as: "set", "push", "pop", "splice", etc.

Integrating the two implementations was not a problem, but one case is problematic. Whenever the value stored at an index of the "local" array changes and I receive an "update" event from the framework, I have to deal with a very costly operation to notify the y-array.

The "y-array" doesn't define a native "set" method. Right now I am reacting to the "update" event with a combination of ".delete(pos)" and ".insert(pos, [value])", which isn't an optimal solution, because whenever I call these two methods, the Yjs observer fires 2 events, and every single time these methods are fired I have to make many additional checks in order to prevent of entering in a loop.

If y-array had a native "set" method, I would need one single check, which would be significantly better in my use-case scenario.

Is there any reason why the "set(pos, value)" method is not defined in the y-array implementation?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions