Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
knockout#225: For debugging, add ability to view value of observables…
… as property of object, but only in debug build of Knockout.
  • Loading branch information
mbest committed Feb 22, 2012
1 parent e9b12ad commit 9e95506
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build/build-linux
Expand Up @@ -13,11 +13,12 @@ cat $SourceFiles >> $OutDebugFile.temp
cat fragments/amd-post.js >> $OutDebugFile.temp

# Now call Google Closure Compiler to produce a minified version
curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --data-urlencode js_code@$OutDebugFile.temp "http://closure-compiler.appspot.com/compile" > $OutMinFile.temp
curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --data-urlencode "js_code=/**@const*/var DEBUG=false;" --data-urlencode js_code@$OutDebugFile.temp "http://closure-compiler.appspot.com/compile" > $OutMinFile.temp

# Finalise each file by prefixing with version header and surrounding in function closure
cp fragments/version-header.js $OutDebugFile
echo "(function(window,document,navigator,undefined){" >> $OutDebugFile
echo "var DEBUG=true;" >> $OutDebugFile
cat $OutDebugFile.temp >> $OutDebugFile
echo "})(window,document,navigator);" >> $OutDebugFile
rm $OutDebugFile.temp
Expand Down
3 changes: 2 additions & 1 deletion build/build-windows.bat
Expand Up @@ -19,11 +19,12 @@ type %AllFiles% >> %OutDebugFile%.temp
type fragments\amd-post.js >> %OutDebugFile%.temp

@rem Now call Google Closure Compiler to produce a minified version
tools\curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --data-urlencode js_code@%OutDebugFile%.temp "http://closure-compiler.appspot.com/compile" > %OutMinFile%.temp
tools\curl -d output_info=compiled_code -d output_format=text -d compilation_level=ADVANCED_OPTIMIZATIONS --data-urlencode "js_code=/**@const*/var DEBUG=false;" --data-urlencode js_code@%OutDebugFile%.temp "http://closure-compiler.appspot.com/compile" > %OutMinFile%.temp

@rem Finalise each file by prefixing with version header and surrounding in function closure
copy /y fragments\version-header.js %OutDebugFile%
echo (function(window,document,navigator,undefined){ >> %OutDebugFile%
echo var DEBUG=true; >> %OutDebugFile%
type %OutDebugFile%.temp >> %OutDebugFile%
echo })(window,document,navigator); >> %OutDebugFile%
del %OutDebugFile%.temp
Expand Down
1 change: 1 addition & 0 deletions src/subscribables/dependentObservable.js
Expand Up @@ -89,6 +89,7 @@ ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunction

dependentObservable["notifySubscribers"](_latestValue, "beforeChange");
_latestValue = newValue;
if (DEBUG) dependentObservable._latestValue = _latestValue;
} finally {
ko.dependencyDetection.end();
}
Expand Down
2 changes: 2 additions & 0 deletions src/subscribables/observable.js
Expand Up @@ -11,6 +11,7 @@ ko.observable = function (initialValue) {
if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
observable.valueWillMutate();
_latestValue = arguments[0];
if (DEBUG) observable._latestValue = _latestValue;
observable.valueHasMutated();
}
return this; // Permits chained assignments
Expand All @@ -21,6 +22,7 @@ ko.observable = function (initialValue) {
return _latestValue;
}
}
if (DEBUG) observable._latestValue = _latestValue;
ko.subscribable.call(observable);
observable.valueHasMutated = function () { observable["notifySubscribers"](_latestValue); }
observable.valueWillMutate = function () { observable["notifySubscribers"](_latestValue, "beforeChange"); }
Expand Down

0 comments on commit 9e95506

Please sign in to comment.