diff --git a/dist/recline.dataset.js b/dist/recline.dataset.js index dfb4e401..963cac53 100644 --- a/dist/recline.dataset.js +++ b/dist/recline.dataset.js @@ -499,11 +499,7 @@ my.Query = Backbone.Model.extend({ var ourfilter = JSON.parse(JSON.stringify(filter)); // not fully specified so use template and over-write if (_.keys(filter).length <= 3) { - ourfilter = _.extend( - // crude deep copy - JSON.parse(JSON.stringify(this._filterTemplates[filter.type])), - ourfilter - ); + ourfilter = _.defaults(ourfilter, this._filterTemplates[filter.type]); } var filters = this.get('filters'); filters.push(ourfilter); @@ -820,12 +816,15 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; }; this.transform = function(editFunc) { - var toUpdate = recline.Data.Transform.mapDocs(this.data, editFunc); - // TODO: very inefficient -- could probably just walk the documents and updates in tandem and update - _.each(toUpdate.updates, function(record, idx) { - self.data[idx] = record; + var dfd = $.Deferred(); + // TODO: should we clone before mapping? Do not see the point atm. + self.data = _.map(self.data, editFunc); + // now deal with deletes (i.e. nulls) + self.data = _.filter(self.data, function(record) { + return record != null; }); - return this.save(toUpdate); + dfd.resolve(); + return dfd.promise(); }; }; diff --git a/dist/recline.js b/dist/recline.js index 17e09693..3f0591ba 100644 --- a/dist/recline.js +++ b/dist/recline.js @@ -1171,12 +1171,15 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {}; }; this.transform = function(editFunc) { - var toUpdate = recline.Data.Transform.mapDocs(this.data, editFunc); - // TODO: very inefficient -- could probably just walk the documents and updates in tandem and update - _.each(toUpdate.updates, function(record, idx) { - self.data[idx] = record; + var dfd = $.Deferred(); + // TODO: should we clone before mapping? Do not see the point atm. + self.data = _.map(self.data, editFunc); + // now deal with deletes (i.e. nulls) + self.data = _.filter(self.data, function(record) { + return record != null; }); - return this.save(toUpdate); + dfd.resolve(); + return dfd.promise(); }; }; @@ -1880,11 +1883,7 @@ my.Query = Backbone.Model.extend({ var ourfilter = JSON.parse(JSON.stringify(filter)); // not fully specified so use template and over-write if (_.keys(filter).length <= 3) { - ourfilter = _.extend( - // crude deep copy - JSON.parse(JSON.stringify(this._filterTemplates[filter.type])), - ourfilter - ); + ourfilter = _.defaults(ourfilter, this._filterTemplates[filter.type]); } var filters = this.get('filters'); filters.push(ourfilter);