Skip to content
Browse files

Do the 'dirty' notification after scheduling evaluation so order of e…

…valuation is maintained.
  • Loading branch information...
1 parent 66aeab3 commit 01dd05090f7f50dae12d48751a7c9b027023bf5b @mbest committed Feb 23, 2012
Showing with 3 additions and 3 deletions.
  1. +3 −3 knockout-deferred-updates.js
View
6 knockout-deferred-updates.js
@@ -190,9 +190,6 @@ var newComputed = function (evaluatorFunctionOrOptions, evaluatorFunctionTarget,
if (_isBeingEvaluated)
return;
_needsEvaluation = true;
- dependentObservable["notifySubscribers"](_latestValue, "dirty");
- if (!_needsEvaluation) // The notification might have triggered an evaluation
- return;
var throttleEvaluationTimeout = dependentObservable['throttleEvaluation'];
if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
clearTimeout(evaluationTimeoutInstance);
@@ -201,6 +198,9 @@ var newComputed = function (evaluatorFunctionOrOptions, evaluatorFunctionTarget,
ko.tasks.processDelayed(evaluateImmediate, true, disposeWhenNodeIsRemoved);
else
evaluateImmediate();
+ dependentObservable["notifySubscribers"](_latestValue, "dirty");

This line is throwing an error.

// knockout-deferred-updates.js:234
// Uncaught TypeError: Object function
dependentObservable() {
        if (arguments.length > 0) {
            set.apply(dependentObservable, arguments);
        } else {
            return get();
        }
    } has no method 'notifySubscribers'

I'm having a hard time reproducing it in jsfiddle, but I can't figure out why it would break my app. I'm including deferred-updates after knockout-2.0.0 just as I did before this change. Any ideas what's going on?

Here's the full stacktrace from Chrome if you're interested:
https://gist.github.com/1927694

Even though the stacktrace says the file is knockout-2.0.0.rc3, I updated the content to the released 2.0.0 version and still got the error.

@mbest
Owner
mbest added a note Feb 27, 2012

It'll break if you have a computed observable that triggers re-evaluation of itself during its initial evaluation. I thought I had fixed it, but it got lost somehow.

@mbest
Owner
mbest added a note Feb 28, 2012

I pushed a fix for it. Let me know if it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ if (!_needsEvaluation && throttleEvaluationTimeout) // The notification might have triggered an evaluation
+ clearTimeout(evaluationTimeoutInstance);
}
function addDependency(subscribable) {

0 comments on commit 01dd050

Please sign in to comment.
Something went wrong with that request. Please try again.