dominictarr / crdt

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

Allow for attaching events for initial rows in set #15

Closed Raynos closed 11 years ago

Raynos commented 11 years ago

Add existing rows to the set later.

This ensures the user has enough time to bind events to "add" and "changes" on the set before those rows are added.

The tradeoff is that you can't synchronously check set.toJSON() for any valid rows until the next tick.

dominictarr commented 11 years ago

hmm, I think it's better to iterate over the set... using next tick leaks implementation details...

when I have this problem I just go

function add (...) {...}
set.forEach(add)
set.on('add', add)

I think a better approach would be to add a function every

set.every(function(item) {
  //this function is called first with all the current items,
  //and THEN when ever an update comes in...
})
Raynos commented 11 years ago

set.every works for me.

dominictarr commented 11 years ago

on second thoughts, every isn't the best name, because that is already on the Array.prototype. what about set.onEach(function (item) {...}) I think that implys events, and forEach... at least it doesn't collide with an existing api.

can you make a fresh pull request for this?

Raynos commented 11 years ago

@dominictarr what about forAll

dominictarr commented 11 years ago

I don't feel that forAll suggests anything about the temporal nature of this method, because for is associated with ordinary iteration.

forAll all sounds like a synonym for forEach or is called once with an array of all the items...

dominictarr commented 11 years ago

@Raynos what do you think about onEach

Raynos commented 11 years ago

onEach is fine

Raynos commented 11 years ago

See #18