Last active
June 3, 2016 01:50
-
-
Save katowulf/936c596071f098738e0695114323ff08 to your computer and use it in GitHub Desktop.
Include old/new values in $firebaseArray::$watch method.
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
angular.factory('Arr', function($firebaseArray) { | |
function Arr(ref) { | |
this.oldVals = {}; | |
return $firebaseArray.call(this, ref); | |
} | |
Arr.prototype.$$process = function(event, rec, prevKey) { | |
$firebaseArray.prototype.$$process.apply(this, arguments); | |
this.oldVals[rec.$id] = rec; | |
}; | |
Arr.prototype.$$getOldVal = function(key) { | |
return this.oldVals.hasOwnProperty(key)? this.oldVals[key] : null; | |
}; | |
Arr.prototype.$$notify = function(event, key, prevChild) { | |
var eventData = {event: event, key: key, oldVal: this.$$getOldVal(key), newVal: this.$getRecord(key)}; | |
if( angular.isDefined(prevChild) ) { | |
eventData.prevChild = prevChild; | |
} | |
angular.forEach(this._observers, function(parts) { | |
parts[0].call(parts[1], eventData); | |
}); | |
}; | |
return $firebaseArray.$extend(Arr); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment