mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Fire $eval only if the value has actually changed on input
This commit is contained in:
parent
e84d3334b0
commit
b225083a21
2 changed files with 18 additions and 6 deletions
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -42,6 +42,15 @@ describe("widget", function(){
|
|||
expect(scope.$get('count')).toEqual(2);
|
||||
});
|
||||
|
||||
it('should not trigger eval if value does not change', function(){
|
||||
compile('<input type="Text" name="name" value="Misko" ng:change="count = count + 1" ng:init="count=0"/>');
|
||||
expect(scope.name).toEqual("Misko");
|
||||
expect(scope.count).toEqual(0);
|
||||
browserTrigger(element, 'keyup');
|
||||
expect(scope.name).toEqual("Misko");
|
||||
expect(scope.count).toEqual(0);
|
||||
});
|
||||
|
||||
it('should allow complex refernce binding', function(){
|
||||
compile('<div ng:init="obj={abc:{}}">'+
|
||||
'<input type="Text" name="obj[\'abc\'].name" value="Misko""/>'+
|
||||
|
|
|
|||
Loading…
Reference in a new issue