baconjs/bacon.js — pull request #356 by skozin (2014-04-15 02:01:22+00:00)
Title: Call subscriptions of dependent nodes after subscriptions of their dependencies

Suppose that we have two observables with one subscriber each:

```coffee
a = new Bacon.Bus
b = a.map true
b.onValue -> console.log "b"
a.onValue -> console.log "a"
a.push 123
```

Currently, the order in which these subscribers will be called is unspecified. However, in a simple case they are called in the order of subscription, so the above code will print `"b"` then `"a"`. Things get more complicated when synchronization is involved:

```coffee
a = new Bacon.Bus
b = a.map yes
c = b.toProperty()
d = Bacon.combineAsArray a, c
e = d.changes()

callOrder = []
log = (name) -> () -> callOrder.push name

e.onValue log "e"
d.onValue log "d"
b.onValue log "b"
c.onValue log "c"
a.onValue log "a"

a.push 123
console.log callOrder

# outputs:
["c", "b", "a", "e", "d"]
```

This patch implements the guarantee that side effects assigned to dependent nodes will always occur after side effects assigned to their dependencies. That is, the first snippet will always output `"a"`, `"b"` and the second `["a", "b", "c", "d", "e"]`, regardless of the order of subscription.

This is implemented by changing `Dispatcher`'s logic so that it processes subscriptions with side effects before other ("internal") subscriptions. The changes are really simple and performance shouldn't be affected.

I think that this behavior is more consistent than the current one. What do you think?