Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 862c9d8

Browse files
committed
refactor(ngModel): move model -> view update from watchFn to watchAction
1 parent 240d589 commit 862c9d8

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/ng/directive/ngModel.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
731731
$exceptionHandler(e);
732732
}
733733
});
734+
if (ctrl.$viewChangeListeners.length > 0 ||
735+
ctrl.$options && ctrl.$options.getterSetter === true
736+
) {
737+
modelToViewAction(ngModelGet($scope));
738+
}
734739
};
735740

736741
/**
@@ -820,19 +825,13 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
820825
}
821826
};
822827

823-
// model -> value
824-
// Note: we cannot use a normal scope.$watch as we want to detect the following:
825-
// 1. scope value is 'a'
826-
// 2. user enters 'b'
827-
// 3. ng-change kicks in and reverts scope value to 'a'
828-
// -> scope value did not change since the last digest as
829-
// ng-change executes in apply phase
830-
// 4. view should be changed back to 'a'
828+
// model -> view
831829
$scope.$watch(function ngModelWatch() {
832-
var modelValue = ngModelGet($scope);
830+
return ngModelGet($scope);
831+
}, ngModelWatchAction, ctrl.$options && ctrl.$options.deepWatch);
833832

833+
function ngModelWatchAction(modelValue) {
834834
// if scope model value and ngModel value are out of sync
835-
// TODO(perf): why not move this to the action fn?
836835
if (modelValue !== ctrl.$modelValue &&
837836
// checks for NaN is needed to allow setting the model to NaN when there's an asyncValidator
838837
(ctrl.$modelValue === ctrl.$modelValue || modelValue === modelValue)
@@ -855,9 +854,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
855854
ctrl.$$runValidators(modelValue, viewValue, noop);
856855
}
857856
}
858-
859-
return modelValue;
860-
});
857+
}
861858
}];
862859

863860

0 commit comments

Comments
 (0)