diff --git a/ampersand-state.js b/ampersand-state.js index 86ce52e..4f6ec48 100644 --- a/ampersand-state.js +++ b/ampersand-state.js @@ -25,6 +25,7 @@ var BBEvents = require('backbone-events-standalone'); var KeyTree = require('key-tree-store'); var arrayNext = require('array-next'); var changeRE = /^change:/; +var isObjectEqual = require('amp-is-object-equal'); function Base(attrs, options) { options || (options = {}); @@ -410,9 +411,11 @@ assign(Base.prototype, BBEvents, { var update = function (options) { options = options || {}; + + var newVal = def.fn.call(self); - if (self._cache[name] !== newVal || !def.cache) { + if (!isObjectEqual(self._cache[name], newVal) || !def.cache) { if (def.cache) { self._previousAttributes[name] = self._cache[name]; } diff --git a/package.json b/package.json index 76feb90..52dd355 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "ampersand-version": "^1.0.0", + "amp-is-object-equal": "^1.0.2", "array-next": "~0.0.1", "backbone-events-standalone": "0.2.2", "key-tree-store": "~0.1.0",