gerich-home / it-depends

Lightweight dependency tracking library for JavaScript
http://it-depends-js.github.io/
Other
1 stars 2 forks source link

Bulk changes block #4

Closed gerich-home closed 8 years ago

gerich-home commented 8 years ago

There should be an ability to write:

var a = itDepends.value(10);
var b = itDepends.value(20);
var c = itDepends.computed(function() {
    return a() + b();
});

var subscription = c.onChange(function(newValue, oldValue) {
    console.log(oldValue + ' -> ' + newValue);
});

a(20); // outputs 30 -> 40
b(30); // outputs 40 -> 50

itDepends.bulkChange(function() {
    console.log('start');
    a(30);
    b(40);
    console.log('a = ' + a());
    console.log('b = ' + b());
    console.log('end');
}); // outputs start, a = 30, b = 40, end, 50 -> 70

a(40); // outputs 70 -> 80
b(50); // outputs 80 -> 90
gerich-home commented 8 years ago

Described proposed feature as a test: https://github.com/gerich-home/it-depends/tree/bulk-change