Skip to content

Instantly share code, notes, and snippets.

@yakovkhalinsky
Last active December 28, 2015 03:39
Show Gist options
  • Save yakovkhalinsky/7436188 to your computer and use it in GitHub Desktop.
Save yakovkhalinsky/7436188 to your computer and use it in GitHub Desktop.
Function to process an aggregate watch in Angular
var WATCHER = function(oldValues, newValues, map) {
var changes, index, value;
changes = {};
if (Array.isArray(oldValues)) {
for (index in oldValues) {
value = oldValues[index];
if (value !== newValues[index]) {
changes[map[index]] = {
oldVal: oldValues[index]
newVal: newValues[index]
};
}
}
} else {
if (oldValues !== newValues) {
changes[map] = newValues;
}
}
return changes;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment