Last active
December 28, 2015 03:39
-
-
Save yakovkhalinsky/7436188 to your computer and use it in GitHub Desktop.
Function to process an aggregate watch in Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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