Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed bubbling within the same collection

  • Loading branch information...
commit d9bbfa2ce4ea378aef2a590b809debf0af1cf984 1 parent c52869a
@masylum authored
Showing with 31 additions and 5 deletions.
  1. +12 −4 backbone.subset.js
  2. +19 −1 test/test.js
View
16 backbone.subset.js
@@ -240,11 +240,19 @@
*/
Subset._proxyReset = function (collection, options) {
options = options || {};
+ var ids
+ , sieved_ids
+ , self = this;
+
+ if (options.model_ids) {
+ ids = _.intersection(this.pluck('id'), options.model_ids);
+ sieved_ids = _.pluck(_.filter(ids, function (id) {
+ return self.sieve(self.get(id));
+ }), 'id');
+ }
- if (collection !== this && !options || (options && !options.noproxy)) {
- if (!options.model_ids || _.intersection(this.pluck('id'), options.model_ids).length) {
- this._resetSubset(_.extend(_.clone(options), {proxied: true}));
- }
+ if ((!options.model_ids || this === collection || sieved_ids.length) && (!options || !options.noproxy)) {
+ this._resetSubset(_.extend(_.clone(options), {proxied: true}));
}
};
View
20 test/test.js
@@ -111,7 +111,7 @@ describe('Subset', function () {
// Initial state
for (var i = 0; i < 2; i++) {
- archived_tasks.add({id: i, archived: i % 2, order: i});
+ archived_tasks.add({id: i, archived: i % 2, urgent: 0,order: i});
}
});
@@ -277,6 +277,24 @@ describe('Subset', function () {
assert.deepEqual(_.pluck(tasks.models, 'cid'), ['c0', 'c1']);
assert.deepEqual(_.pluck(archived_tasks.models, 'cid'), ['c1']);
});
+
+ it('resets only relevant collections', function () {
+ tasks.bind('reset', inc('tasks'));
+ archived_tasks.bind('reset', inc('archived_tasks'));
+ urgent_tasks.bind('reset', inc('urgent_tasks'));
+
+ console.log('YAI');
@masylum Owner
masylum added a note

I´m lame

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ urgent_tasks.reset([ {id: 2, archived: 0, urgent: 1, order: 2}
+ , {id: 3, archived: 0, urgent: 1, order: 3}]);
+
+ assert.equal(happened.tasks, 1);
+ assert.equal(happened.archived_tasks, 0);
+ assert.equal(happened.urgent_tasks, 1);
+
+ assertElements(tasks.pluck('id'), [0, 1, 2, 3]);
+ assertElements(archived_tasks.pluck('id'), [1]);
+ assertElements(urgent_tasks.pluck('id'), [2, 3]);
+ });
});
describe('Live updating subset membership', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.