diff options
| author | Vojta Jina | 2011-11-30 12:23:58 -0800 |
|---|---|---|
| committer | Vojta Jina | 2012-01-23 11:11:27 -0800 |
| commit | 0196411dbe179afe24f4faa6d6503ff3f69472da (patch) | |
| tree | 8c79c809b884af8385ad2695c4885b18a5efa369 /src/service | |
| parent | 992c790f0786fa45c1cc3710f29bf49c7c322ba7 (diff) | |
| download | angular.js-0196411dbe179afe24f4faa6d6503ff3f69472da.tar.bz2 | |
refactor(scope.$watch): rearrange arguments passed into watcher (newValue, oldValue, scope)
As scopes are injected into controllers now, you have the reference anyway, so having scope as first argument makes no senseā¦
Breaks $watcher gets arguments in different order (newValue, oldValue, scope)
Diffstat (limited to 'src/service')
| -rw-r--r-- | src/service/formFactory.js | 2 | ||||
| -rw-r--r-- | src/service/scope.js | 16 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/service/formFactory.js b/src/service/formFactory.js index 565b22a4..5d64131e 100644 --- a/src/service/formFactory.js +++ b/src/service/formFactory.js @@ -377,7 +377,7 @@ function $FormFactoryProvider() { // Set the state to something we know will change to get the process going. widget.$modelValue = Number.NaN; // watch for scope changes and update the view appropriately - modelScope.$watch(scopeGet, function(scope, value) { + modelScope.$watch(scopeGet, function(value) { if (!equals(widget.$modelValue, value)) { widget.$modelValue = value; widget.$parseModel ? widget.$parseModel() : (widget.$viewValue = value); diff --git a/src/service/scope.js b/src/service/scope.js index 089e4a41..f59417bc 100644 --- a/src/service/scope.js +++ b/src/service/scope.js @@ -207,7 +207,7 @@ function $RootScopeProvider(){ scope.counter = 0; expect(scope.counter).toEqual(0); - scope.$watch('name', function(scope, newValue, oldValue) { counter = counter + 1; }); + scope.$watch('name', function(newValue, oldValue) { counter = counter + 1; }); expect(scope.counter).toEqual(0); scope.$digest(); @@ -231,22 +231,26 @@ function $RootScopeProvider(){ * the `watchExpression` changes. * * - `string`: Evaluated as {@link guide/dev_guide.expressions expression} - * - `function(scope, newValue, oldValue)`: called with current `scope` an previous and - * current values as parameters. + * - `function(newValue, oldValue, scope)`: called with current and previous values as parameters. * @returns {function()} Returns a deregistration function for this listener. */ $watch: function(watchExp, listener) { var scope = this, get = compileToFn(watchExp, 'watch'), - listenFn = compileToFn(listener || noop, 'listener'), array = scope.$$watchers, watcher = { - fn: listenFn, + fn: listener, last: initWatchVal, get: get, exp: watchExp }; + // in the case user pass string, we need to compile it, do we really need this ? + if (!isFunction(listener)) { + var listenFn = compileToFn(listener || noop, 'listener'); + watcher.fn = function(newVal, oldVal, scope) {listenFn(scope);}; + } + if (!array) { array = scope.$$watchers = []; } @@ -341,7 +345,7 @@ function $RootScopeProvider(){ if ((value = watch.get(current)) !== (last = watch.last) && !equals(value, last)) { dirty = true; watch.last = copy(value); - watch.fn(current, value, ((last === initWatchVal) ? value : last)); + watch.fn(value, ((last === initWatchVal) ? value : last), current); if (ttl < 5) { logIdx = 4 - ttl; if (!watchLog[logIdx]) watchLog[logIdx] = []; |
