angular-data
Advanced tools
Comparing version 1.5.1 to 1.5.2
@@ -0,1 +1,9 @@ | ||
##### 1.5.2 - 03 December 2014 | ||
###### Backwards compatible bug fixes | ||
- #262 - store.previousAttributes is storing references to nested objects, preventing changes from being detected | ||
###### Other | ||
- Change detection "should" work on nested attributes now | ||
##### 1.5.1 - 02 December 2014 | ||
@@ -2,0 +10,0 @@ |
@@ -20,2 +20,6 @@ // Copyright 2012 Google Inc. | ||
// Fixed use of "delete" keyword for IE8 compatibility | ||
// Exposed diffObjectFromOldObject on the exported object | ||
// Added the "equals" argument to diffObjectFromOldObject to be used to check equality | ||
// Added a way to to define a default equality operator for diffObjectFromOldObject | ||
// Added a way in diffObjectFromOldObject to ignore changes to certain properties | ||
// Removed all code related to: | ||
@@ -31,2 +35,8 @@ // - ArrayObserver | ||
var equalityFn = function (a, b) { | ||
return a === b; | ||
}; | ||
var blacklist = []; | ||
// Detect and do basic sanity checking on Object/Array.observe. | ||
@@ -131,3 +141,16 @@ function detectObjectObserve() { | ||
function diffObjectFromOldObject(object, oldObject) { | ||
function isBlacklisted(prop, bl) { | ||
if (!bl || !bl.length) { | ||
return false; | ||
} | ||
var matches; | ||
for (var i = 0; i < bl.length; i++) { | ||
if ((Object.prototype.toString.call(bl[i]) === '[object RegExp]' && bl[i].test(prop)) || bl[i] === prop) { | ||
return matches = prop; | ||
} | ||
} | ||
return !!matches; | ||
} | ||
function diffObjectFromOldObject(object, oldObject, equals, bl) { | ||
var added = {}; | ||
@@ -140,5 +163,8 @@ var removed = {}; | ||
if (newValue !== undefined && newValue === oldObject[prop]) | ||
if (isBlacklisted(prop, bl)) | ||
continue; | ||
if (newValue !== undefined && (equals ? equals(newValue, oldObject[prop]) : newValue === oldObject[prop])) | ||
continue; | ||
if (!(prop in object)) { | ||
@@ -149,3 +175,3 @@ removed[prop] = undefined; | ||
if (newValue !== oldObject[prop]) | ||
if (equals ? !equals(newValue, oldObject[prop]) : newValue !== oldObject[prop]) | ||
changed[prop] = newValue; | ||
@@ -158,2 +184,5 @@ } | ||
if (isBlacklisted(prop, bl)) | ||
continue; | ||
added[prop] = object[prop]; | ||
@@ -468,3 +497,3 @@ } | ||
oldValues = this.oldObject_; | ||
diff = diffObjectFromOldObject(this.value_, this.oldObject_); | ||
diff = diffObjectFromOldObject(this.value_, this.oldObject_, equalityFn, blacklist); | ||
} | ||
@@ -587,2 +616,9 @@ | ||
global.Observer = Observer; | ||
global.diffObjectFromOldObject = diffObjectFromOldObject; | ||
global.setEqualityFn = function (fn) { | ||
equalityFn = fn; | ||
}; | ||
global.setBlacklist = function (bl) { | ||
blacklist = bl; | ||
}; | ||
global.Observer.runEOM_ = runEOM; | ||
@@ -589,0 +625,0 @@ global.Observer.observerSentinel_ = observerSentinel; // for testing. |
{ | ||
"name": "angular-data", | ||
"description": "Data store for Angular.js.", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"homepage": "http://angular-data.pseudobry.com", | ||
@@ -23,3 +23,3 @@ "repository": { | ||
"grunt": "0.4.5", | ||
"grunt-browserify": "3.2.0", | ||
"grunt-browserify": "3.2.1", | ||
"grunt-contrib-clean": "0.6.0", | ||
@@ -33,8 +33,8 @@ "grunt-contrib-concat": "0.5.0", | ||
"grunt-karma": "0.9.0", | ||
"grunt-karma-coveralls": "2.5.2", | ||
"grunt-karma-coveralls": "2.5.3", | ||
"jit-grunt": "0.9.0", | ||
"karma": "0.12.24", | ||
"karma": "0.12.28", | ||
"karma-chai": "0.1.0", | ||
"karma-chrome-launcher": "0.1.5", | ||
"karma-coverage": "0.2.6", | ||
"karma-chrome-launcher": "0.1.6", | ||
"karma-coverage": "0.2.7", | ||
"karma-firefox-launcher": "0.1.3", | ||
@@ -44,3 +44,3 @@ "karma-mocha": "0.1.9", | ||
"karma-script-launcher": "0.1.0", | ||
"karma-sinon": "1.0.3", | ||
"karma-sinon": "1.0.4", | ||
"karma-spec-reporter": "0.0.13", | ||
@@ -47,0 +47,0 @@ "time-grunt": "1.0.0" |
@@ -11,3 +11,3 @@ ## angular-data [](http://waffle.io/jmdobry/angular-data) [](http://waffle.io/jmdobry/angular-data) [](http://waffle.io/jmdobry/angular-data) | ||
__Latest Release:__ [1.5.1](https://github.com/jmdobry/angular-data/releases/tag/1.5.1) | ||
__Latest Release:__ [1.5.2](https://github.com/jmdobry/angular-data/releases/tag/1.5.2) | ||
@@ -14,0 +14,0 @@ Angular-data is finally 1.0.! |
@@ -129,3 +129,3 @@ function errorPrefix(resourceName) { | ||
resource.completedQueries[id] = new Date().getTime(); | ||
resource.previousAttributes[id] = DSUtils.deepMixIn({}, created); | ||
resource.previousAttributes[id] = DSUtils.copy(created); | ||
resource.saved[id] = DSUtils.updateTimestamp(resource.saved[id]); | ||
@@ -132,0 +132,0 @@ return DS.get(resourceName, id); |
@@ -133,3 +133,3 @@ function errorPrefix(resourceName, id) { | ||
var saved = DS.inject(definition.name, attrs, options); | ||
resource.previousAttributes[id] = DSUtils.deepMixIn({}, saved); | ||
resource.previousAttributes[id] = DSUtils.copy(saved); | ||
resource.saved[id] = DSUtils.updateTimestamp(resource.saved[id]); | ||
@@ -136,0 +136,0 @@ resource.observers[id].discardChanges(); |
@@ -113,3 +113,3 @@ function errorPrefix(resourceName, id) { | ||
var id = updated[definition.idAttribute]; | ||
resource.previousAttributes[id] = DSUtils.deepMixIn({}, updated); | ||
resource.previousAttributes[id] = DSUtils.copy(updated); | ||
resource.saved[id] = DSUtils.updateTimestamp(resource.saved[id]); | ||
@@ -116,0 +116,0 @@ resource.observers[id].discardChanges(); |
@@ -66,3 +66,3 @@ function errorPrefix(resourceName) { | ||
DS.store[resourceName].observers[id].deliver(); | ||
var diff = DSUtils.diffObjectFromOldObject(item, DS.store[resourceName].previousAttributes[id], options.ignoredChanges); | ||
var diff = DSUtils.diffObjectFromOldObject(item, DS.store[resourceName].previousAttributes[id], DSUtils.deepEquals, options.ignoredChanges); | ||
DSUtils.forEach(diff, function (changeset, name) { | ||
@@ -69,0 +69,0 @@ var toKeep = []; |
@@ -152,3 +152,3 @@ var observe = require('../../../lib/observe-js/observe-js'); | ||
} | ||
resource.previousAttributes[id] = angular.copy(attrs); | ||
resource.previousAttributes[id] = DSUtils.copy(attrs); | ||
@@ -168,4 +168,3 @@ DSUtils.deepMixIn(item, attrs); | ||
if (definition.resetHistoryOnInject) { | ||
resource.previousAttributes[id] = {}; | ||
DSUtils.deepMixIn(resource.previousAttributes[id], attrs); | ||
resource.previousAttributes[id] = DSUtils.copy(attrs); | ||
if (resource.changeHistories[id].length) { | ||
@@ -172,0 +171,0 @@ DSUtils.forEach(resource.changeHistories[id], function (changeRecord) { |
@@ -59,19 +59,11 @@ var DSErrors = require('./errors'); | ||
var find = require('mout/array/find'); | ||
var isRegExp = require('mout/lang/isRegExp'); | ||
var deepEquals = angular.equals; | ||
function isBlacklisted(prop, blacklist) { | ||
if (!blacklist || !blacklist.length) { | ||
return false; | ||
} | ||
var matches = find(blacklist, function (blItem) { | ||
if ((isRegExp(blItem) && blItem.test(prop)) || blItem === prop) { | ||
return prop; | ||
} | ||
}); | ||
return !!matches; | ||
} | ||
var observe = require('../lib/observe-js/observe-js'); | ||
observe.setEqualityFn(deepEquals); | ||
module.exports = ['$q', function ($q) { | ||
return { | ||
@@ -100,3 +92,2 @@ isBoolean: require('mout/lang/isBoolean'), | ||
filter: require('mout/array/filter'), | ||
find: find, | ||
toLookup: require('mout/array/toLookup'), | ||
@@ -109,2 +100,3 @@ remove: require('mout/array/remove'), | ||
keys: require('mout/object/keys'), | ||
observe: observe, | ||
_: function (parent, options) { | ||
@@ -170,49 +162,5 @@ var _this = this; | ||
}, | ||
diffObjectFromOldObject: function (object, oldObject, blacklist) { | ||
var added = {}; | ||
var removed = {}; | ||
var changed = {}; | ||
blacklist = blacklist || []; | ||
for (var prop in oldObject) { | ||
var newValue = object[prop]; | ||
if (isBlacklisted(prop, blacklist)) { | ||
continue; | ||
} | ||
if (newValue !== undefined && deepEquals(newValue, oldObject[prop])) { | ||
continue; | ||
} | ||
if (!(prop in object)) { | ||
removed[prop] = undefined; | ||
continue; | ||
} | ||
if (!deepEquals(newValue, oldObject[prop])) { | ||
changed[prop] = newValue; | ||
} | ||
} | ||
for (var prop2 in object) { | ||
if (prop2 in oldObject) { | ||
continue; | ||
} | ||
if (isBlacklisted(prop2, blacklist)) { | ||
continue; | ||
} | ||
added[prop2] = object[prop2]; | ||
} | ||
return { | ||
added: added, | ||
removed: removed, | ||
changed: changed | ||
}; | ||
}, | ||
diffObjectFromOldObject: observe.diffObjectFromOldObject, | ||
Events: Events | ||
}; | ||
}]; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
575920
13821