Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var computed = ko.computed(function() {
- readSomeObservables(); //<-- if these change, notify computed
- ko.stopCollectingDependencies();
- readSomeMoreObservables(); //<-- if these change, do not notify computed
- ko.resumeCollectingDependencies();
- });
- window.setTimeout(function() {
- readSomeMoreObservables();
- }, 0);
- // this one is updated
- // if any of the subscribeables used in readSomeMoreObservables changes
- // but that is hopefully cheap
- var tempComputed = ko.computed(function() {
- readSomeMoreObservables();
- });
- var computed = ko.computed(function() {
- readSomeObservables(); //<-- if these change, notify computed
- // do not update on readSomeMoreObservables
- tempComputed.peek();
- });
- var computed = ko.computed(function() {
- var a = readSomeObservables(); //<-- if these change, notify computed
- var b;
- // capture any dependencies from readSomeMoreObservables
- // in a temporary computed, then immediately dispose
- // of it to release those captured dependencies
- ko.computed(function() { b = readSomeMoreObservables(); }).dispose();
- return a + b; // or whatever
- });
- it('Should not subscribe to subscribeables called by ignore', function() {
- var observableInner = ko.observable('initial'),
- observableOuter = ko.observable(),
- called = 0,
- computedInner = ko.computed(function() { return observableInner(); }),
- computedOuter = ko.computed(function() {
- called += 1;
- // read dependend
- observableOuter();
- // read ignored
- var result = ko.dependencyDetection.ignore(computedInner, null)
- expect(result).toEqual('initial');
- return true;
- });
- expect(called).toEqual(1);
- // update the one we are depending on
- observableOuter(1);
- expect(called).toEqual(2);
- // update the inner one which should trigger an update to computedInner but not to computedOuter
- observableInner('ignore');
- expect(called).toEqual(2);
- });
- var observableTwoInitialState = this.observableTwo();
- this.computed = ko.computed(function() {
- return this.observableOne() + observableTwoInitialState;
- }, this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement