backbone.partial-fetch
Advanced tools
Comparing version
@@ -35,2 +35,12 @@ (function () { | ||
if (_.isFunction(options.filter)) { | ||
filtered_collection = this.filter(options.filter); | ||
} else { | ||
filtered_collection = this.filter(function (item) { | ||
return _.all(_.keys(options.filter), function (key) { | ||
return item.get(key) === options.filter[key]; | ||
}); | ||
}); | ||
} | ||
if (!options.url) { | ||
@@ -44,8 +54,2 @@ if (_.isFunction(this.url)) { | ||
filtered_collection = this.filter(function (item) { | ||
return _.all(_.keys(options.filter), function (key) { | ||
return item.get(key) === options.filter[key]; | ||
}); | ||
}); | ||
options.success = function (resp) { | ||
@@ -52,0 +56,0 @@ var method = options.reset ? 'reset' : 'set' |
{ | ||
"name": "backbone.partial-fetch", | ||
"description": "Partial fetcher for backbone", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "Pau ramon <masylum@gmail.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Enrico Stano", | ||
"email": "enricostn@gmail.com" | ||
} | ||
], | ||
"keywords": ["backbone", "ender", "teambox"], | ||
@@ -7,0 +13,0 @@ "repository": {"type": "git", "url": "git://github.com/masylum/Backbone.PartialFetch.git"}, |
@@ -32,3 +32,3 @@ /*global it, describe, before, beforeEach*/ | ||
describe('url', function () { | ||
it('throws if its not a function', function() { | ||
it('throws if its not a function', function () { | ||
tasks.url = 'foo'; | ||
@@ -40,3 +40,3 @@ assert.throws(function () { | ||
it('gets the filter to the url', function() { | ||
it('gets the filter to the url', function () { | ||
var filter = {archived: true}; | ||
@@ -57,3 +57,3 @@ | ||
describe('filter', function () { | ||
it('defaults to no filtering', function() { | ||
it('defaults to no filtering', function () { | ||
gently.expect(tasks, 'url', function (options) { | ||
@@ -69,6 +69,28 @@ assert.deepEqual(options, {}); | ||
}); | ||
it('uses a custom filter function if given', function () { | ||
var filter = function (item) { | ||
return item.get('archived') === false; | ||
} | ||
, resp = [{id: 0, archived: false}]; | ||
gently.expect(tasks, 'sync', function (method, context, options) { | ||
assert.equal(method, 'read'); | ||
assert.equal(context, tasks); | ||
assert.deepEqual(options.filter, filter); | ||
options.success(resp); | ||
}); | ||
gently.expect(tasks, 'remove', function (to_remove, options) { | ||
assert.deepEqual(to_remove, [1]); | ||
}); | ||
gently.expect(tasks, 'set', function (resp, options) { | ||
assert.deepEqual(resp, resp); | ||
assert.equal(options.remove, false); | ||
}); | ||
tasks.partialFetch({filter: filter}); | ||
}); | ||
}); | ||
describe('smart updating', function () { | ||
it('uses Backbones `set` with `remove` set to false', function() { | ||
it('uses Backbones `set` with `remove` set to false', function () { | ||
gently.expect(tasks, 'sync', function (method, context, options) { | ||
@@ -87,3 +109,3 @@ assert.equal(method, 'read'); | ||
it('does not send the url all along', function() { | ||
it('does not send the url all along', function () { | ||
gently.expect(tasks, 'sync', function (method, context, options) { | ||
@@ -98,3 +120,3 @@ options.success(tasks.models); | ||
it('uses Backbones `reset` if option set', function() { | ||
it('uses Backbones `reset` if option set', function () { | ||
gently.expect(tasks, 'sync', function (method, context, options) { | ||
@@ -113,3 +135,3 @@ assert.equal(method, 'read'); | ||
it('calculates wich data has to be removed', function() { | ||
it('calculates wich data has to be removed', function () { | ||
var filter = {archived: false} | ||
@@ -116,0 +138,0 @@ , resp = [{id: 0, archived: false}]; |
10662
10.42%195
14.04%