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

SharedState - add new set type #67

Open
b-ma opened this issue Oct 4, 2023 · 1 comment
Open

SharedState - add new set type #67

b-ma opened this issue Oct 4, 2023 · 1 comment

Comments

@b-ma
Copy link
Contributor

b-ma commented Oct 4, 2023

Should allow to maintain a collection of items (i.e. add(item), delete(item)) in a kind of "atomic" fashion.

For now, if we do something like:

collection.onAttach(async state => {
  const item = state.get('item');
  const myList = this.global.get('myList');

  if (myList.indexOf(item) === -1) {
    myList.push(item);
  }

  await this.global.set({ myList });
}, true);

Multiple consecutive calls just can erase the modifications from each others. We could have something like:

collection.onAttach(async state => {
  const item = state.get('item');
  const myList = this.global.get('myList');
  await myList.add(item);
}, true);

Another option would be to use a collection, but where everyone is able to delete a state, not only the owner. Probably that's the most straightforward to implement:

server.stateManager.register('my-list', schema, { enforceOwnership: false });
@b-ma
Copy link
Contributor Author

b-ma commented Oct 4, 2023

Another option would be to use a collection, but where everyone is able to delete a state, not only the owner. Probably that's the most straightforward to implement:

server.stateManager.register('my-list', schema, { shareOwnership: true });

This does not work as expected as when an owner disconnects, all states owned by the node are deleted, which is good. But if everyone is owner, the states are deleted each time a single node disconnect, which is not what we want...

To Be Continued...

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