In certain situations there is no point in subscribing or unsubscribing immediately.
We should postpone deep subscriptions until a change was made.
For the case of bulkChange subscriptions/unsubscriptions should be postponed until the end of bulk change.
Example 1
Given the following definitions:
var x = [];
for (var j = 0; j < dependenciesCount; j++) {
x.push(itDepends.value(-1));
}
var a = itDepends.computed(function() {
var z = 0;
for (var j = 0; j < dependenciesCount; j++) {
z += x[j]();
}
return z;
});
var b = itDepends.value(true);
var c = itDepends.computed(function() {
return b() ? a() : 0;
});
the following scenarios should work with approximately the same performance:
c.onChange(function() {}); // triggers massive subscriptions currently
b.write(false); // but all of them get disabled here
b.write(false);
c.onChange(function() {});
Example 2
Given the following definitions:
var x = [];
for (var j = 0; j < dependenciesCount; j++) {
x.push(itDepends.value(-1));
}
var a = itDepends.computed(function() {
var z = 0;
for (var j = 0; j < dependenciesCount; j++) {
z += x[j]();
}
return z;
});
var b = itDepends.value(false);
var c = itDepends.computed(function() {
return b() ? a() : 0;
});
var s = a.onChange(function() {});
x[0].write(1);
the following scenarios should also work with approximately the same performance:
s.disable(); // should not unsubscribe from a and all x[i] immediately!
var s2 = c.onChange(function() {}); // because the replacement subscription is created here
b.write(true); // but becomes active only here
var s2 = c.onChange(function() {});
b.write(true);
s.disable(); // does not trigger massive unsubscriptions currently
In certain situations there is no point in subscribing or unsubscribing immediately. We should postpone deep subscriptions until a change was made.
For the case of
bulkChange
subscriptions/unsubscriptions should be postponed until the end of bulk change.Given the following definitions:
the following scenarios should work with approximately the same performance:
Given the following definitions:
the following scenarios should also work with approximately the same performance: