Skip to content

Commit

Permalink
Fixes #36.
Browse files Browse the repository at this point in the history
Stable Version 0.7.1
  • Loading branch information
jmdobry committed Feb 27, 2014
1 parent e8b3962 commit 046f8e6
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 57 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
##### 0.7.1 - 26 February 2014

###### Backwards compatible bug fixes
- #36 - Fixed inconsistencies in `DS.filter` when using skip or limit in the query

##### 0.7.0 - 24 February 2014

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

###### Backwards API changes
###### Backwards compatible API changes
- #34 - Added `DS.ejectAll(resourceName, params)`
- #33 - Added `DS.destroyAll(resourceName, params[, options])`
- #35 - Add options for asynchronous getter methods to return data without putting it into the data store
Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ module.exports = function (grunt) {
banner: '/**\n' +
'* @author Jason Dobry <jason.dobry@gmail.com>\n' +
'* @file angular-data.min.js\n' +
'* @version <%= pkg.version %> - Homepage <http://jmdobry.github.io/angular-data/>\n' +
'* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/angular-data>\n' +
'* @version <%= pkg.version %> - Homepage <http://angular-data.codetrain.io/>\n' +
'* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>\n' +
'* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>\n' +
'*\n' +
'* @overview Data store for Angular.js.\n' +
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__Data store for Angular.js.__

__Current version:__ 0.6.0
__Current version:__ 0.7.1

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

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Jason Dobry",
"name": "angular-data",
"description": "Data store for Angular.js.",
"version": "0.7.0",
"version": "0.7.1",
"homepage": "http://jmdobry.github.io/angular-data/",
"repository": {
"type": "git",
Expand Down
40 changes: 22 additions & 18 deletions dist/angular-data.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @author Jason Dobry <jason.dobry@gmail.com>
* @file angular-data.js
* @version 0.7.0 - Homepage <http://jmdobry.github.io/angular-data/>
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/angular-data>
* @version 0.7.1 - Homepage <http://angular-data.codetrain.io/>
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
*
* @overview Data store for Angular.js.
*/
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){
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){
(function (global){
// Copyright 2012 Google Inc.
//
Expand Down Expand Up @@ -491,7 +491,7 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ

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

Expand Down Expand Up @@ -2524,7 +2524,7 @@ function DSProvider() {

module.exports = DSProvider;

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

/**
Expand Down Expand Up @@ -2725,7 +2725,7 @@ function digest() {

module.exports = digest;

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

function _eject(definition, resource, id) {
Expand Down Expand Up @@ -3046,11 +3046,15 @@ function filter(resourceName, params, options) {

// Apply 'limit' and 'skip'
if (this.utils.isNumber(params.query.limit) && this.utils.isNumber(params.query.skip)) {
filtered = this.utils.slice(filtered, params.query.skip, params.query.skip + params.query.limit);
filtered = this.utils.slice(filtered, params.query.skip, Math.min(filtered.length, params.query.skip + params.query.limit));
} else if (this.utils.isNumber(params.query.limit)) {
filtered = this.utils.slice(filtered, 0, params.query.limit);
filtered = this.utils.slice(filtered, 0, Math.min(filtered.length, params.query.limit));
} else if (this.utils.isNumber(params.query.skip)) {
filtered = this.utils.slice(filtered, params.query.skip);
if (params.query.skip < filtered.length) {
filtered = this.utils.slice(filtered, params.query.skip);
} else {
filtered = [];
}
}

return filtered;
Expand Down Expand Up @@ -3450,7 +3454,7 @@ function inject(resourceName, attrs, options) {

module.exports = inject;

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

/**
Expand Down Expand Up @@ -3629,8 +3633,8 @@ function previous(resourceName, id) {
module.exports = previous;

},{}],"errors":[function(require,module,exports){
module.exports=require('hIh4e1');
},{}],"hIh4e1":[function(require,module,exports){
module.exports=require('ht0wMj');
},{}],"ht0wMj":[function(require,module,exports){
/**
* @doc function
* @id errors.types:UnhandledError
Expand Down Expand Up @@ -3810,7 +3814,7 @@ module.exports = [function () {
* @id angular-data
* @name angular-data
* @description
* __Version:__ 0.7.0
* __Version:__ 0.7.1
*
* ## Install
*
Expand All @@ -3829,7 +3833,7 @@ module.exports = [function () {
* Load `dist/angular-data.js` or `dist/angular-data.min.js` onto your web page after Angular.js.
*
* #### Manual download
* Download angular-data.0.7.0.js from the [Releases](https://github.com/jmdobry/angular-data/releases)
* Download angular-data.0.7.1.js from the [Releases](https://github.com/jmdobry/angular-data/releases)
* section of the angular-data GitHub project.
*
* ## Load into Angular
Expand Down Expand Up @@ -3883,7 +3887,9 @@ module.exports = [function () {

})(window, window.angular);

},{"./adapters/http":27,"./datastore":36,"./errors":"hIh4e1","./utils":"uE/lJt"}],"uE/lJt":[function(require,module,exports){
},{"./adapters/http":27,"./datastore":36,"./errors":"ht0wMj","./utils":"iWjGJZ"}],"utils":[function(require,module,exports){
module.exports=require('iWjGJZ');
},{}],"iWjGJZ":[function(require,module,exports){
module.exports = [function () {
return {
isString: angular.isString,
Expand Down Expand Up @@ -3963,6 +3969,4 @@ module.exports = [function () {
};
}];

},{"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){
module.exports=require('uE/lJt');
},{}]},{},[52])
},{"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])
8 changes: 4 additions & 4 deletions dist/angular-data.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-data",
"description": "Data store for Angular.js.",
"version": "0.7.0",
"version": "0.7.1",
"homepage": "http://github.com/jmdobry/angular-data",
"repository": {
"type": "git",
Expand All @@ -23,7 +23,7 @@
"grunt-cli": "0.1.13",
"grunt-browserify": "1.3.1",
"grunt-contrib-clean": "0.5.0",
"load-grunt-tasks": "0.3.0",
"load-grunt-tasks": "0.4.0",
"grunt-docular": "0.1.2",
"grunt-contrib-uglify": "0.3.2",
"grunt-contrib-jshint": "0.8.0",
Expand All @@ -37,13 +37,13 @@
"grunt-karma": "~0.6.2",
"karma-chai": "0.1.0",
"mocha": "~1.17.1",
"karma-coverage": "~0.1.2",
"karma-coverage": "~0.2.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-karma-coveralls": "~2.3.0",
"grunt-karma-coveralls": "~2.4.0",
"karma-mocha": "~0.1.1",
"karma-sinon": "~1.0.2",
"time-grunt": "~0.2.9",
"browserify": "~3.30.2"
"browserify": "~3.31.2"
},
"scripts": {
"test": "node node_modules/grunt-cli/bin/grunt test"
Expand Down
10 changes: 7 additions & 3 deletions src/datastore/sync_methods/filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ function filter(resourceName, params, options) {

// Apply 'limit' and 'skip'
if (this.utils.isNumber(params.query.limit) && this.utils.isNumber(params.query.skip)) {
filtered = this.utils.slice(filtered, params.query.skip, params.query.skip + params.query.limit);
filtered = this.utils.slice(filtered, params.query.skip, Math.min(filtered.length, params.query.skip + params.query.limit));
} else if (this.utils.isNumber(params.query.limit)) {
filtered = this.utils.slice(filtered, 0, params.query.limit);
filtered = this.utils.slice(filtered, 0, Math.min(filtered.length, params.query.limit));
} else if (this.utils.isNumber(params.query.skip)) {
filtered = this.utils.slice(filtered, params.query.skip);
if (params.query.skip < filtered.length) {
filtered = this.utils.slice(filtered, params.query.skip);
} else {
filtered = [];
}
}

return filtered;
Expand Down
45 changes: 23 additions & 22 deletions test/integration/datastore/sync_methods/filter/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('DS.filter(resourceName, params[, options])', function () {
var errorPrefix = 'DS.filter(resourceName, params[, options]): ';

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

DS.filter('post', {});

done();
});
it('should return an empty array if the query has never been made before', function (done) {
it('should return an empty array if the query has never been made before', function () {
$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]);

assert.deepEqual(DS.filter('post', {
Expand Down Expand Up @@ -104,9 +102,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
}), [
p1
], 'should no longer be empty');
done();
});
it('should correctly apply "where" predicates', function (done) {
it('should correctly apply "where" predicates', function () {
assert.doesNotThrow(function () {
DS.inject('post', p1);
DS.inject('post', p2);
Expand Down Expand Up @@ -188,10 +185,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
params.query.where = { age: { garbage: 'should have no effect' } };

assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should return all elements');

done();
});
it('should correctly apply "orderBy" predicates', function (done) {
it('should correctly apply "orderBy" predicates', function () {
assert.doesNotThrow(function () {
DS.inject('post', p1);
DS.inject('post', p2);
Expand Down Expand Up @@ -230,10 +225,8 @@ describe('DS.filter(resourceName, params[, options])', function () {
params.query.orderBy = ['author'];

assert.deepEqual(DS.filter('post', params), [p4, p1, p3, p2], 'should accept an array of a string and sort in ascending for strings');

done();
});
it('should correctly apply "skip" predicates', function (done) {
it('should correctly apply "skip" predicates', function () {
assert.doesNotThrow(function () {
DS.inject('post', p1);
DS.inject('post', p2);
Expand All @@ -257,10 +250,8 @@ describe('DS.filter(resourceName, params[, options])', function () {

params.query.skip = 4;
assert.deepEqual(DS.filter('post', params), [], 'should skip 4');

done();
});
it('should correctly apply "limit" predicates', function (done) {
it('should correctly apply "limit" predicates', function () {
assert.doesNotThrow(function () {
DS.inject('post', p1);
DS.inject('post', p2);
Expand All @@ -284,10 +275,8 @@ describe('DS.filter(resourceName, params[, options])', function () {

params.query.limit = 4;
assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should limit to 4');

done();
});
it('should correctly apply "limit" and "skip" predicates together', function (done) {
it('should correctly apply "limit" and "skip" predicates together', function () {
assert.doesNotThrow(function () {
DS.inject('post', p1);
DS.inject('post', p2);
Expand All @@ -314,9 +303,23 @@ describe('DS.filter(resourceName, params[, options])', function () {
params.query.skip = 3;
assert.deepEqual(DS.filter('post', params), [p4], 'should limit to 1 and skip 3');

done();
params.query.limit = 8;
params.query.skip = 0;
assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should return all items');

params.query.limit = 1;
params.query.skip = 5;
assert.deepEqual(DS.filter('post', params), [], 'should return nothing if skip if greater than the number of items');

params.query.limit = 8;
delete params.query.skip;
assert.deepEqual(DS.filter('post', params), [p1, p2, p3, p4], 'should return all items');

delete params.query.limit;
params.query.skip = 5;
assert.deepEqual(DS.filter('post', params), [], 'should return nothing if skip if greater than the number of items');
});
it('should allow custom "where" filter function', function (done) {
it('should allow custom "where" filter function', function () {
DS.defineResource({
name: 'comment',
filter: function (resourceName, where, attrs) {
Expand Down Expand Up @@ -344,7 +347,5 @@ describe('DS.filter(resourceName, params[, options])', function () {
};

assert.deepEqual(DS.filter('comment', params), [p1, p2], 'should keep p1 and p2');

done();
});
});

0 comments on commit 046f8e6

Please sign in to comment.