Skip to content

Instantly share code, notes, and snippets.

@petebacondarwin
Created September 30, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petebacondarwin/b855bc134b8b89503d8b to your computer and use it in GitHub Desktop.
Save petebacondarwin/b855bc134b8b89503d8b to your computer and use it in GitHub Desktop.
var oldModelValue, newModelValue, counter;
function watchModelFn(scope) {
newModelValue = ngModelGet(scope);
if (
!updatingFromTheView &&
!(newModelValue === undefined && $valid === false) &&
!modelEquals(newModelValue, oldModelValue)
) {
counter++;
oldModelValue = modelCopy(newModelValue);
}
updatingFromTheView = false;
return counter;
}
function watchHandler() {
ctrl.$modelValue = newModelValue;
var newViewValue = runFormatters(ctrl.$modelValue);
if (!viewEquals(newViewValue, viewCopy(ctrl.$viewValue))) {
ctrl.$viewValue = newViewValue;
render();
runValidators($viewValue);
}
}
// Simple things
simpleEquals = function(lhs, rhs) { return lhs === rhs; };
simpleCopy = function(val) { return val; };
// Objects
objectEquals = angular.equals
objectCopy = angular.copy
// More complex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment