backbone.rel
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -10,3 +10,2 @@ /** | ||
, root = this | ||
, cache = {} | ||
, _ = root._; | ||
@@ -24,25 +23,2 @@ | ||
/** | ||
* Computes the caching key | ||
* | ||
* @param {Model|Collection} self | ||
* @param {String} key | ||
* @return {String} | ||
*/ | ||
function cacheId(self, key) { | ||
return [self.cid, key].join('-'); | ||
} | ||
/** | ||
* Creates a handler that cleans the cache | ||
* | ||
* @param {String} cache_id | ||
* @return {Function} | ||
*/ | ||
function expireCache(cache_id) { | ||
return function () { | ||
delete cache[cache_id]; | ||
}; | ||
} | ||
/** | ||
* Get the relationship options | ||
@@ -131,4 +107,3 @@ * | ||
RelHandler.prototype.handleHasMany = function () { | ||
var options = getOptions(this.self, 'hasMany', this.key) | ||
, cache_id; | ||
var options = getOptions(this.self, 'hasMany', this.key); | ||
@@ -147,10 +122,3 @@ function filter(el) { | ||
cache_id = cacheId(this.self, this.key); | ||
if (!cache[cache_id]) { | ||
cache[cache_id] = options.collection.filter(_.bind(options.filter || filter, this.self)); | ||
options.collection.bind('all', expireCache(cache_id)); | ||
} | ||
return cache[cache_id]; | ||
return options.collection.filter(_.bind(options.filter || filter, this.self)); | ||
}; | ||
@@ -157,0 +125,0 @@ |
{ | ||
"name": "backbone.rel", | ||
"description": "Lightweight relationship assistant for your backbone applications", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Pau ramon <masylum@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": ["Maxim lolls <collsmaxim@gmail.com>"], |
@@ -28,10 +28,2 @@ /*global it, describe, before, beforeEach*/ | ||
it('should expire the cache', function () { | ||
assert.deepEqual(_.pluck(users.get(0).rel('tasks'), 'id'), [2, 4]); | ||
tasks.add({id: 6, user_id: 0}, {silent: true}); | ||
assert.deepEqual(_.pluck(users.get(0).rel('tasks'), 'id'), [2, 4]); | ||
tasks.add({id: 7, user_id: 0}); | ||
assert.deepEqual(_.pluck(users.get(0).rel('tasks'), 'id'), [2, 4, 6, 7]); | ||
}); | ||
it('returns the owned projects for a given user', function () { | ||
@@ -38,0 +30,0 @@ assert.deepEqual(_.pluck(users.get(0).rel('owned_projects'), 'id'), [0, 1]); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22832
505