From b225083a21844bdc710b02337dfa1bef5883baf3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 8 Dec 2010 16:14:18 -0800 Subject: Fire $eval only if the value has actually changed on input --- src/widgets.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') 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){ -- cgit v1.2.3