Skip to content
This repository has been archived by the owner on Nov 12, 2019. It is now read-only.

When removing document which is in a set, filter key is removed #30

Open
mmalecki opened this issue Nov 16, 2013 · 4 comments
Open

When removing document which is in a set, filter key is removed #30

mmalecki opened this issue Nov 16, 2013 · 4 comments

Comments

@mmalecki
Copy link
Contributor

Since doc.set(key, null) is called here, doc.on('remove') listeners get a documents without the filter property.

@dominictarr
Copy link
Owner

hmm, do you mean that listeners have no way to know what the value was?

@mmalecki
Copy link
Contributor Author

Yeah. For example, if I createSet('resource', 'Registration') and remove documents belonging to it, the doc's remove event will be emitted without resource property in state (doc.get('resource') === null).

@dominictarr
Copy link
Owner

Hmm, so you'd rather emit the remove event before the thing is actually removed?
... this creates a potential race condition...
I always try and emit the event after the state is stable again,
because anything can happen in the event listener, i.e. the item can join another group.
what if, instead, the remove event provided the set that it was in,

set.on('remove', function (item, value, key) {
  //item was removed from the key=value set
})

I think you could do the same stuff, but it wouldn't expose you to difficult bugs.

@mmalecki
Copy link
Contributor Author

Yeah, that's why this isn't a pull request - I'm not really sure how to fix that without creating the race condition you mentioned.

I do use the set.on('remove') walk-around.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants