kefirjs / kefir

A Reactive Programming library for JavaScript
https://kefirjs.github.io/kefir/
MIT License
1.87k stars 97 forks source link

.combine with "passive sources" doesn't work well as a solution for manual atomic updates #98

Closed rpominov closed 9 years ago

rpominov commented 9 years ago

97 — issue about atomic updates.

The .combine method has a feature that allows one to pass "passive sources" in a second array (see docs). One of original purposes of this feature was to allow to create "atomic update" behavior manually.

But turns out it doesn't work well with this use case as for now, for instance:

var a = Kefir.sequentially(100, [1,2,3]);
var b = a.map(function(val){return val + 2});
var c = a.map(function(val){return val * 2});
var d = Kefir.combine([b], [c], function(b, c){return [b,c]});
d.log()

Combine {_dispatcher: Dispatcher, _active: true, _alive: true, _activeCount: 1, _sources: Array[2]…}
// expecting [3, 2]
kefir.js:841 [combine] <value> [4, 2] // expecting [4, 4]
kefir.js:841 [combine] <value> [5, 4] // expecting [5, 6]
kefir.js:843 [combine] <end>

This happened after we deprecated Kefir.sampledBy(passive, active, fn) and introduced passive arg in Kefir.combine but in different order — Kefir.combine(active, passive, fn). The order change has introduced the issue. And as deprecated Kefir.sampledBy also implemented on top of Kefir.combine the issue is present in it too.

rpominov commented 9 years ago

Fixed in master. Going to release a new version after the transition to ES6 (that currently going on) is complete.

rpominov commented 9 years ago

fixed in 2.2.0