|
@@ -2,7 +2,6 @@ var config = require('./config'),
|
|
|
Emitter = require('emitter'),
|
|
Emitter = require('emitter'),
|
|
|
toString = Object.prototype.toString,
|
|
toString = Object.prototype.toString,
|
|
|
aproto = Array.prototype,
|
|
aproto = Array.prototype,
|
|
|
- arrayMutators = ['push','pop','shift','unshift','splice','sort','reverse'],
|
|
|
|
|
templates = {}
|
|
templates = {}
|
|
|
|
|
|
|
|
var arrayAugmentations = {
|
|
var arrayAugmentations = {
|
|
@@ -16,6 +15,20 @@ var arrayAugmentations = {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+var arrayMutators = ['push','pop','shift','unshift','splice','sort','reverse'],
|
|
|
|
|
+ mutationInterceptors = {}
|
|
|
|
|
+
|
|
|
|
|
+arrayMutators.forEach(function (method) {
|
|
|
|
|
+ mutationInterceptors[method] = function () {
|
|
|
|
|
+ var result = aproto[method].apply(this, arguments)
|
|
|
|
|
+ this.emit('mutate', {
|
|
|
|
|
+ method: method,
|
|
|
|
|
+ args: aproto.slice.call(arguments),
|
|
|
|
|
+ result: result
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* get accurate type of an object
|
|
* get accurate type of an object
|
|
|
*/
|
|
*/
|
|
@@ -87,17 +100,7 @@ module.exports = {
|
|
|
var method, i = arrayMutators.length
|
|
var method, i = arrayMutators.length
|
|
|
while (i--) {
|
|
while (i--) {
|
|
|
method = arrayMutators[i]
|
|
method = arrayMutators[i]
|
|
|
- /* jshint loopfunc: true */
|
|
|
|
|
- collection[method] = (function (method) {
|
|
|
|
|
- return function () {
|
|
|
|
|
- var result = aproto[method].apply(this, arguments)
|
|
|
|
|
- this.emit('mutate', {
|
|
|
|
|
- method: method,
|
|
|
|
|
- args: aproto.slice.call(arguments),
|
|
|
|
|
- result: result
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- })(method)
|
|
|
|
|
|
|
+ collection[method] = mutationInterceptors[method]
|
|
|
}
|
|
}
|
|
|
for (method in arrayAugmentations) {
|
|
for (method in arrayAugmentations) {
|
|
|
collection[method] = arrayAugmentations[method]
|
|
collection[method] = arrayAugmentations[method]
|