dominictarr / crdt

Commutative Replicated Data Types for easy collaborative/distributed systems.
MIT License
836 stars 43 forks source link

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

Open mmalecki opened 10 years ago

mmalecki commented 10 years ago

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

dominictarr commented 10 years ago

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

mmalecki commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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.