Skip to content

Commit 046f8e6

Browse files
committed
Fixes #36.
Stable Version 0.7.1
1 parent e8b3962 commit 046f8e6

File tree

9 files changed

+71
-57
lines changed

9 files changed

+71
-57
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
##### 0.7.1 - 26 February 2014
2+
3+
###### Backwards compatible bug fixes
4+
- #36 - Fixed inconsistencies in `DS.filter` when using skip or limit in the query
5+
16
##### 0.7.0 - 24 February 2014
27

38
###### Breaking API changes
49
- `DS.eject(resourceName, id)` can now only eject individual items
510

6-
###### Backwards API changes
11+
###### Backwards compatible API changes
712
- #34 - Added `DS.ejectAll(resourceName, params)`
813
- #33 - Added `DS.destroyAll(resourceName, params[, options])`
914
- #35 - Add options for asynchronous getter methods to return data without putting it into the data store

Gruntfile.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ module.exports = function (grunt) {
5151
banner: '/**\n' +
5252
'* @author Jason Dobry <[email protected]>\n' +
5353
'* @file angular-data.min.js\n' +
54-
'* @version <%= pkg.version %> - Homepage <http://jmdobry.github.io/angular-data/>\n' +
55-
'* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/angular-data>\n' +
54+
'* @version <%= pkg.version %> - Homepage <http://angular-data.codetrain.io/>\n' +
55+
'* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>\n' +
5656
'* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>\n' +
5757
'*\n' +
5858
'* @overview Data store for Angular.js.\n' +

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
__Data store for Angular.js.__
44

5-
__Current version:__ 0.6.0
5+
__Current version:__ 0.7.1
66

77
Angular-data is in a pre-1.0.0 development stage; the API is fluctuating, not a lot of tests yet, etc.
88

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Jason Dobry",
33
"name": "angular-data",
44
"description": "Data store for Angular.js.",
5-
"version": "0.7.0",
5+
"version": "0.7.1",
66
"homepage": "http://jmdobry.github.io/angular-data/",
77
"repository": {
88
"type": "git",

dist/angular-data.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* @author Jason Dobry <[email protected]>
33
* @file angular-data.js
4-
* @version 0.7.0 - Homepage <http://jmdobry.github.io/angular-data/>
5-
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/angular-data>
4+
* @version 0.7.1 - Homepage <http://angular-data.codetrain.io/>
5+
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
66
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77
*
88
* @overview Data store for Angular.js.
99
*/
10-
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"salHtg":[function(require,module,exports){
10+
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"QYwGEY":[function(require,module,exports){
1111
(function (global){
1212
// Copyright 2012 Google Inc.
1313
//
@@ -491,7 +491,7 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ
491491

492492
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
493493
},{}],"observejs":[function(require,module,exports){
494-
module.exports=require('salHtg');
494+
module.exports=require('QYwGEY');
495495
},{}],3:[function(require,module,exports){
496496
var indexOf = require('./indexOf');
497497

@@ -2524,7 +2524,7 @@ function DSProvider() {
25242524

25252525
module.exports = DSProvider;
25262526

2527-
},{"../utils":"uE/lJt","./async_methods":33,"./sync_methods":45}],37:[function(require,module,exports){
2527+
},{"../utils":"iWjGJZ","./async_methods":33,"./sync_methods":45}],37:[function(require,module,exports){
25282528
var errorPrefix = 'DS.changes(resourceName, id): ';
25292529

25302530
/**
@@ -2725,7 +2725,7 @@ function digest() {
27252725

27262726
module.exports = digest;
27272727

2728-
},{"observejs":"salHtg"}],40:[function(require,module,exports){
2728+
},{"observejs":"QYwGEY"}],40:[function(require,module,exports){
27292729
var errorPrefix = 'DS.eject(resourceName, id): ';
27302730

27312731
function _eject(definition, resource, id) {
@@ -3046,11 +3046,15 @@ function filter(resourceName, params, options) {
30463046

30473047
// Apply 'limit' and 'skip'
30483048
if (this.utils.isNumber(params.query.limit) && this.utils.isNumber(params.query.skip)) {
3049-
filtered = this.utils.slice(filtered, params.query.skip, params.query.skip + params.query.limit);
3049+
filtered = this.utils.slice(filtered, params.query.skip, Math.min(filtered.length, params.query.skip + params.query.limit));
30503050
} else if (this.utils.isNumber(params.query.limit)) {
3051-
filtered = this.utils.slice(filtered, 0, params.query.limit);
3051+
filtered = this.utils.slice(filtered, 0, Math.min(filtered.length, params.query.limit));
30523052
} else if (this.utils.isNumber(params.query.skip)) {
3053-
filtered = this.utils.slice(filtered, params.query.skip);
3053+
if (params.query.skip < filtered.length) {
3054+
filtered = this.utils.slice(filtered, params.query.skip);
3055+
} else {
3056+
filtered = [];
3057+
}
30543058
}
30553059

30563060
return filtered;
@@ -3450,7 +3454,7 @@ function inject(resourceName, attrs, options) {
34503454

34513455
module.exports = inject;
34523456

3453-
},{"observejs":"salHtg"}],47:[function(require,module,exports){
3457+
},{"observejs":"QYwGEY"}],47:[function(require,module,exports){
34543458
var errorPrefix = 'DS.lastModified(resourceName[, id]): ';
34553459

34563460
/**
@@ -3629,8 +3633,8 @@ function previous(resourceName, id) {
36293633
module.exports = previous;
36303634

36313635
},{}],"errors":[function(require,module,exports){
3632-
module.exports=require('hIh4e1');
3633-
},{}],"hIh4e1":[function(require,module,exports){
3636+
module.exports=require('ht0wMj');
3637+
},{}],"ht0wMj":[function(require,module,exports){
36343638
/**
36353639
* @doc function
36363640
* @id errors.types:UnhandledError
@@ -3810,7 +3814,7 @@ module.exports = [function () {
38103814
* @id angular-data
38113815
* @name angular-data
38123816
* @description
3813-
* __Version:__ 0.7.0
3817+
* __Version:__ 0.7.1
38143818
*
38153819
* ## Install
38163820
*
@@ -3829,7 +3833,7 @@ module.exports = [function () {
38293833
* Load `dist/angular-data.js` or `dist/angular-data.min.js` onto your web page after Angular.js.
38303834
*
38313835
* #### Manual download
3832-
* Download angular-data.0.7.0.js from the [Releases](https://github.com/jmdobry/angular-data/releases)
3836+
* Download angular-data.0.7.1.js from the [Releases](https://github.com/jmdobry/angular-data/releases)
38333837
* section of the angular-data GitHub project.
38343838
*
38353839
* ## Load into Angular
@@ -3883,7 +3887,9 @@ module.exports = [function () {
38833887

38843888
})(window, window.angular);
38853889

3886-
},{"./adapters/http":27,"./datastore":36,"./errors":"hIh4e1","./utils":"uE/lJt"}],"uE/lJt":[function(require,module,exports){
3890+
},{"./adapters/http":27,"./datastore":36,"./errors":"ht0wMj","./utils":"iWjGJZ"}],"utils":[function(require,module,exports){
3891+
module.exports=require('iWjGJZ');
3892+
},{}],"iWjGJZ":[function(require,module,exports){
38873893
module.exports = [function () {
38883894
return {
38893895
isString: angular.isString,
@@ -3963,6 +3969,4 @@ module.exports = [function () {
39633969
};
39643970
}];
39653971

3966-
},{"mout/array/contains":3,"mout/array/filter":4,"mout/array/slice":7,"mout/array/sort":8,"mout/array/toLookup":9,"mout/lang/isEmpty":14,"mout/object/deepMixIn":21,"mout/object/forOwn":23,"mout/string/makePath":25,"mout/string/upperCase":26}],"utils":[function(require,module,exports){
3967-
module.exports=require('uE/lJt');
3968-
},{}]},{},[52])
3972+
},{"mout/array/contains":3,"mout/array/filter":4,"mout/array/slice":7,"mout/array/sort":8,"mout/array/toLookup":9,"mout/lang/isEmpty":14,"mout/object/deepMixIn":21,"mout/object/forOwn":23,"mout/string/makePath":25,"mout/string/upperCase":26}]},{},[52])

dist/angular-data.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-data",
33
"description": "Data store for Angular.js.",
4-
"version": "0.7.0",
4+
"version": "0.7.1",
55
"homepage": "http://github.com/jmdobry/angular-data",
66
"repository": {
77
"type": "git",
@@ -23,7 +23,7 @@
2323
"grunt-cli": "0.1.13",
2424
"grunt-browserify": "1.3.1",
2525
"grunt-contrib-clean": "0.5.0",
26-
"load-grunt-tasks": "0.3.0",
26+
"load-grunt-tasks": "0.4.0",
2727
"grunt-docular": "0.1.2",
2828
"grunt-contrib-uglify": "0.3.2",
2929
"grunt-contrib-jshint": "0.8.0",
@@ -37,13 +37,13 @@
3737
"grunt-karma": "~0.6.2",
3838
"karma-chai": "0.1.0",
3939
"mocha": "~1.17.1",
40-
"karma-coverage": "~0.1.2",
40+
"karma-coverage": "~0.2.0",
4141
"grunt-contrib-watch": "~0.5.3",
42-
"grunt-karma-coveralls": "~2.3.0",
42+
"grunt-karma-coveralls": "~2.4.0",
4343
"karma-mocha": "~0.1.1",
4444
"karma-sinon": "~1.0.2",
4545
"time-grunt": "~0.2.9",
46-
"browserify": "~3.30.2"
46+
"browserify": "~3.31.2"
4747
},
4848
"scripts": {
4949
"test": "node node_modules/grunt-cli/bin/grunt test"

src/datastore/sync_methods/filter/index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ function filter(resourceName, params, options) {
131131

132132
// Apply 'limit' and 'skip'
133133
if (this.utils.isNumber(params.query.limit) && this.utils.isNumber(params.query.skip)) {
134-
filtered = this.utils.slice(filtered, params.query.skip, params.query.skip + params.query.limit);
134+
filtered = this.utils.slice(filtered, params.query.skip, Math.min(filtered.length, params.query.skip + params.query.limit));
135135
} else if (this.utils.isNumber(params.query.limit)) {
136-
filtered = this.utils.slice(filtered, 0, params.query.limit);
136+
filtered = this.utils.slice(filtered, 0, Math.min(filtered.length, params.query.limit));
137137
} else if (this.utils.isNumber(params.query.skip)) {
138-
filtered = this.utils.slice(filtered, params.query.skip);
138+
if (params.query.skip < filtered.length) {
139+
filtered = this.utils.slice(filtered, params.query.skip);
140+
} else {
141+
filtered = [];
142+
}
139143
}
140144

141145
return filtered;

test/integration/datastore/sync_methods/filter/index.test.js

+23-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('DS.filter(resourceName, params[, options])', function () {
22
var errorPrefix = 'DS.filter(resourceName, params[, options]): ';
33

4-
it('should throw an error when method pre-conditions are not met', function (done) {
4+
it('should throw an error when method pre-conditions are not met', function () {
55
assert.throws(function () {
66
DS.filter('does not exist', {});
77
}, DS.errors.RuntimeError, errorPrefix + 'does not exist is not a registered resource!');
@@ -65,10 +65,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
6565
});
6666

6767
DS.filter('post', {});
68-
69-
done();
7068
});
71-
it('should return an empty array if the query has never been made before', function (done) {
69+
it('should return an empty array if the query has never been made before', function () {
7270
$httpBackend.expectGET('http://test.angular-cache.com/posts?query=%7B%22where%22:%7B%22author%22:%7B%22%3D%3D%22:%22John%22%7D%7D%7D').respond(200, [p1]);
7371

7472
assert.deepEqual(DS.filter('post', {
@@ -104,9 +102,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
104102
}), [
105103
p1
106104
], 'should no longer be empty');
107-
done();
108105
});
109-
it('should correctly apply "where" predicates', function (done) {
106+
it('should correctly apply "where" predicates', function () {
110107
assert.doesNotThrow(function () {
111108
DS.inject('post', p1);
112109
DS.inject('post', p2);
@@ -188,10 +185,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
188185
params.query.where = { age: { garbage: 'should have no effect' } };
189186

190187
assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should return all elements');
191-
192-
done();
193188
});
194-
it('should correctly apply "orderBy" predicates', function (done) {
189+
it('should correctly apply "orderBy" predicates', function () {
195190
assert.doesNotThrow(function () {
196191
DS.inject('post', p1);
197192
DS.inject('post', p2);
@@ -230,10 +225,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
230225
params.query.orderBy = ['author'];
231226

232227
assert.deepEqual(DS.filter('post', params), [p4, p1, p3, p2], 'should accept an array of a string and sort in ascending for strings');
233-
234-
done();
235228
});
236-
it('should correctly apply "skip" predicates', function (done) {
229+
it('should correctly apply "skip" predicates', function () {
237230
assert.doesNotThrow(function () {
238231
DS.inject('post', p1);
239232
DS.inject('post', p2);
@@ -257,10 +250,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
257250

258251
params.query.skip = 4;
259252
assert.deepEqual(DS.filter('post', params), [], 'should skip 4');
260-
261-
done();
262253
});
263-
it('should correctly apply "limit" predicates', function (done) {
254+
it('should correctly apply "limit" predicates', function () {
264255
assert.doesNotThrow(function () {
265256
DS.inject('post', p1);
266257
DS.inject('post', p2);
@@ -284,10 +275,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
284275

285276
params.query.limit = 4;
286277
assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should limit to 4');
287-
288-
done();
289278
});
290-
it('should correctly apply "limit" and "skip" predicates together', function (done) {
279+
it('should correctly apply "limit" and "skip" predicates together', function () {
291280
assert.doesNotThrow(function () {
292281
DS.inject('post', p1);
293282
DS.inject('post', p2);
@@ -314,9 +303,23 @@ describe('DS.filter(resourceName, params[, options])', function () {
314303
params.query.skip = 3;
315304
assert.deepEqual(DS.filter('post', params), [p4], 'should limit to 1 and skip 3');
316305

317-
done();
306+
params.query.limit = 8;
307+
params.query.skip = 0;
308+
assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should return all items');
309+
310+
params.query.limit = 1;
311+
params.query.skip = 5;
312+
assert.deepEqual(DS.filter('post', params), [], 'should return nothing if skip if greater than the number of items');
313+
314+
params.query.limit = 8;
315+
delete params.query.skip;
316+
assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should return all items');
317+
318+
delete params.query.limit;
319+
params.query.skip = 5;
320+
assert.deepEqual(DS.filter('post', params), [], 'should return nothing if skip if greater than the number of items');
318321
});
319-
it('should allow custom "where" filter function', function (done) {
322+
it('should allow custom "where" filter function', function () {
320323
DS.defineResource({
321324
name: 'comment',
322325
filter: function (resourceName, where, attrs) {
@@ -344,7 +347,5 @@ describe('DS.filter(resourceName, params[, options])', function () {
344347
};
345348

346349
assert.deepEqual(DS.filter('comment', params), [p1, p2], 'should keep p1 and p2');
347-
348-
done();
349350
});
350351
});

0 commit comments

Comments
 (0)