diff options
| author | Misko Hevery | 2010-12-08 16:14:18 -0800 | 
|---|---|---|
| committer | Misko Hevery | 2010-12-11 08:27:52 -0800 | 
| commit | b225083a21844bdc710b02337dfa1bef5883baf3 (patch) | |
| tree | 56afc35227f6290409809fbfb984363e98dba045 /src/widgets.js | |
| parent | e84d3334b0604de26821451158a2ea8c3360431f (diff) | |
| download | angular.js-b225083a21844bdc710b02337dfa1bef5883baf3.tar.bz2 | |
Fire $eval only if the value has actually changed on input
Diffstat (limited to 'src/widgets.js')
| -rw-r--r-- | src/widgets.js | 15 | 
1 files changed, 9 insertions, 6 deletions
diff --git a/src/widgets.js b/src/widgets.js index 04353bd5..2d9f53f7 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -373,7 +373,7 @@ function optionsAccessor(scope, element) {  function noopAccessor() { return { get: noop, set: noop }; } -var textWidget = inputWidget('keyup change', modelAccessor, valueAccessor, initWidgetValue()), +var textWidget = inputWidget('keyup change', modelAccessor, valueAccessor, initWidgetValue(), true),      buttonWidget = inputWidget('click', noopAccessor, noopAccessor, noop),      INPUT_TYPE = {        'text':            textWidget, @@ -451,7 +451,7 @@ function radioInit(model, view, element) {       expect(binding('checkboxCount')).toBe('1');     });   */ -function inputWidget(events, modelAccessor, viewAccessor, initFn) { +function inputWidget(events, modelAccessor, viewAccessor, initFn, dirtyChecking) {    return function(element) {      var scope = this,          model = modelAccessor(scope, element), @@ -463,10 +463,13 @@ function inputWidget(events, modelAccessor, viewAccessor, initFn) {      // Don't register a handler if we are a button (noopAccessor) and there is no action      if (action || modelAccessor !== noopAccessor) {        element.bind(events, function (){ -        model.set(view.get()); -        lastValue = model.get(); -        scope.$tryEval(action, element); -        scope.$root.$eval(); +        var value = view.get(); +        if (!dirtyChecking || value != lastValue) { +          model.set(value); +          lastValue = model.get(); +          scope.$tryEval(action, element); +          scope.$root.$eval(); +        }        });      }      scope.$watch(model.get, function(value){  | 
