Skip to content

Commit

Permalink
Fixes #258 Fixes #259
Browse files Browse the repository at this point in the history
Stable Version 1.5.1.
  • Loading branch information
jmdobry committed Dec 2, 2014
1 parent 7ecf97d commit 2bb8fb7
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 97 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
##### 1.5.1 - 02 December 2014

###### Backwards compatible API changes
- #259 - Added the "contains", "notContains", "|contains", and "|notContains" operators

###### Backwards compatible bug fixes
- #258 - No changes detected on nested fields

##### 1.5.0 - 01 December 2014

###### Backwards compatible API changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Unlike Backbone and Ember Models, angular-data does not require the use of gette

Supporting relations, computed properties, model lifecycle control and a slew of other features, angular-data is the tool for giving your data the respect it deserves.

__Latest Release:__ [1.5.0](https://github.com/jmdobry/angular-data/releases/tag/1.5.0)
__Latest Release:__ [1.5.1](https://github.com/jmdobry/angular-data/releases/tag/1.5.1)

Angular-data is finally 1.0.!

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": "1.5.0",
"version": "1.5.1",
"homepage": "http://angular-data.pseudobry.com/",
"repository": {
"type": "git",
Expand Down
83 changes: 38 additions & 45 deletions dist/angular-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @author Jason Dobry <jason.dobry@gmail.com>
* @file angular-data.js
* @version 1.5.0 - Homepage <http://angular-data.pseudobry.com/>
* @version 1.5.1 - Homepage <http://angular-data.pseudobry.com/>
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
*
Expand Down Expand Up @@ -988,7 +988,7 @@ var mixIn = require('../object/mixIn');
var flags = '';
flags += r.multiline ? 'm' : '';
flags += r.global ? 'g' : '';
flags += r.ignorecase ? 'i' : '';
flags += r.ignoreCase ? 'i' : '';
return new RegExp(r.source, flags);
}

Expand Down Expand Up @@ -4258,64 +4258,55 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
};
}
if (DSUtils.isObject(clause)) {
DSUtils.forEach(clause, function (val, op) {
DSUtils.forEach(clause, function (term, op) {
var expr;
var isOr = op[0] === '|';
var val = attrs[field];
op = isOr ? op.substr(1) : op;
if (op === '==') {
keep = first ? (attrs[field] == val) : keep && (attrs[field] == val);
expr = val == term;
} else if (op === '===') {
keep = first ? (attrs[field] === val) : keep && (attrs[field] === val);
expr = val === term;
} else if (op === '!=') {
keep = first ? (attrs[field] != val) : keep && (attrs[field] != val);
expr = val != term;
} else if (op === '!==') {
keep = first ? (attrs[field] !== val) : keep && (attrs[field] !== val);
expr = val !== term;
} else if (op === '>') {
keep = first ? (attrs[field] > val) : keep && (attrs[field] > val);
expr = val > term;
} else if (op === '>=') {
keep = first ? (attrs[field] >= val) : keep && (attrs[field] >= val);
expr = val >= term;
} else if (op === '<') {
keep = first ? (attrs[field] < val) : keep && (attrs[field] < val);
expr = val < term;
} else if (op === '<=') {
keep = first ? (attrs[field] <= val) : keep && (attrs[field] <= val);
expr = val <= term;
} else if (op === 'in') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep && val.indexOf(attrs[field]) !== -1;
if (DSUtils.isString(term)) {
expr = term.indexOf(val) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep && DSUtils.contains(val, attrs[field]);
expr = DSUtils.contains(term, val);
}
} else if (op === 'notIn') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep && val.indexOf(attrs[field]) === -1;
if (DSUtils.isString(term)) {
expr = term.indexOf(val) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep && !DSUtils.contains(val, attrs[field]);
expr = !DSUtils.contains(term, val);
}
} else if (op === '|==') {
keep = first ? (attrs[field] == val) : keep || (attrs[field] == val);
} else if (op === '|===') {
keep = first ? (attrs[field] === val) : keep || (attrs[field] === val);
} else if (op === '|!=') {
keep = first ? (attrs[field] != val) : keep || (attrs[field] != val);
} else if (op === '|!==') {
keep = first ? (attrs[field] !== val) : keep || (attrs[field] !== val);
} else if (op === '|>') {
keep = first ? (attrs[field] > val) : keep || (attrs[field] > val);
} else if (op === '|>=') {
keep = first ? (attrs[field] >= val) : keep || (attrs[field] >= val);
} else if (op === '|<') {
keep = first ? (attrs[field] < val) : keep || (attrs[field] < val);
} else if (op === '|<=') {
keep = first ? (attrs[field] <= val) : keep || (attrs[field] <= val);
} else if (op === '|in') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep || val.indexOf(attrs[field]) !== -1;
} else if (op === 'contains') {
if (DSUtils.isString(term)) {
expr = (val || '').indexOf(term) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep || DSUtils.contains(val, attrs[field]);
expr = DSUtils.contains(val, term);
}
} else if (op === '|notIn') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep || val.indexOf(attrs[field]) === -1;
} else if (op === 'notContains') {
if (DSUtils.isString(term)) {
expr = (val || '').indexOf(term) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep || !DSUtils.contains(val, attrs[field]);
expr = !DSUtils.contains(val, term);
}
}
if (expr !== undefined) {
keep = first ? expr : (isOr ? keep || expr : keep && expr);
}
first = false;
});
}
Expand Down Expand Up @@ -6769,10 +6760,9 @@ function _inject(definition, resource, attrs, options) {
} else {
item = {};
}
resource.previousAttributes[id] = {};
resource.previousAttributes[id] = angular.copy(attrs);

DSUtils.deepMixIn(item, attrs);
DSUtils.deepMixIn(resource.previousAttributes[id], attrs);

resource.collection.push(item);

Expand Down Expand Up @@ -7824,6 +7814,7 @@ var toPromisify = [

var find = require('mout/array/find');
var isRegExp = require('mout/lang/isRegExp');
var deepEquals = angular.equals;

function isBlacklisted(prop, blacklist) {
if (!blacklist || !blacklist.length) {
Expand Down Expand Up @@ -7853,6 +7844,7 @@ module.exports = ['$q', function ($q) {
upperCase: require('mout/string/upperCase'),
pascalCase: require('mout/string/pascalCase'),
deepMixIn: require('mout/object/deepMixIn'),
deepEquals: deepEquals,
mixIn: require('mout/object/mixIn'),
forEach: angular.forEach,
pick: require('mout/object/pick'),
Expand All @@ -7866,6 +7858,7 @@ module.exports = ['$q', function ($q) {
slice: require('mout/array/slice'),
sort: require('mout/array/sort'),
guid: require('mout/random/guid'),
copy: angular.copy,
keys: require('mout/object/keys'),
_: function (parent, options) {
var _this = this;
Expand Down Expand Up @@ -7940,7 +7933,7 @@ module.exports = ['$q', function ($q) {
continue;
}

if (newValue !== undefined && newValue === oldObject[prop]) {
if (newValue !== undefined && deepEquals(newValue, oldObject[prop])) {
continue;
}

Expand All @@ -7949,7 +7942,7 @@ module.exports = ['$q', function ($q) {
continue;
}

if (newValue !== oldObject[prop]) {
if (!deepEquals(newValue, oldObject[prop])) {
changed[prop] = newValue;
}
}
Expand Down
8 changes: 4 additions & 4 deletions dist/angular-data.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion guide/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<i class="icon-wrench icon-white"></i> API <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li class="nav-header">Angular-data - 1.5.0</li>
<li class="nav-header">Angular-data - 1.5.1</li>
<li>
<a href="/documentation/api/angular-data/angular-data">Overview</a>
</li>
Expand Down
4 changes: 2 additions & 2 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": "1.5.0",
"version": "1.5.1",
"homepage": "http://angular-data.pseudobry.com",
"repository": {
"type": "git",
Expand Down Expand Up @@ -47,6 +47,6 @@
"test": "grunt test"
},
"dependencies": {
"mout": "0.10.0"
"mout": "0.11.0"
}
}
69 changes: 30 additions & 39 deletions src/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,64 +96,55 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
};
}
if (DSUtils.isObject(clause)) {
DSUtils.forEach(clause, function (val, op) {
DSUtils.forEach(clause, function (term, op) {
var expr;
var isOr = op[0] === '|';
var val = attrs[field];
op = isOr ? op.substr(1) : op;
if (op === '==') {
keep = first ? (attrs[field] == val) : keep && (attrs[field] == val);
expr = val == term;
} else if (op === '===') {
keep = first ? (attrs[field] === val) : keep && (attrs[field] === val);
expr = val === term;
} else if (op === '!=') {
keep = first ? (attrs[field] != val) : keep && (attrs[field] != val);
expr = val != term;
} else if (op === '!==') {
keep = first ? (attrs[field] !== val) : keep && (attrs[field] !== val);
expr = val !== term;
} else if (op === '>') {
keep = first ? (attrs[field] > val) : keep && (attrs[field] > val);
expr = val > term;
} else if (op === '>=') {
keep = first ? (attrs[field] >= val) : keep && (attrs[field] >= val);
expr = val >= term;
} else if (op === '<') {
keep = first ? (attrs[field] < val) : keep && (attrs[field] < val);
expr = val < term;
} else if (op === '<=') {
keep = first ? (attrs[field] <= val) : keep && (attrs[field] <= val);
expr = val <= term;
} else if (op === 'in') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep && val.indexOf(attrs[field]) !== -1;
if (DSUtils.isString(term)) {
expr = term.indexOf(val) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep && DSUtils.contains(val, attrs[field]);
expr = DSUtils.contains(term, val);
}
} else if (op === 'notIn') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep && val.indexOf(attrs[field]) === -1;
if (DSUtils.isString(term)) {
expr = term.indexOf(val) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep && !DSUtils.contains(val, attrs[field]);
expr = !DSUtils.contains(term, val);
}
} else if (op === '|==') {
keep = first ? (attrs[field] == val) : keep || (attrs[field] == val);
} else if (op === '|===') {
keep = first ? (attrs[field] === val) : keep || (attrs[field] === val);
} else if (op === '|!=') {
keep = first ? (attrs[field] != val) : keep || (attrs[field] != val);
} else if (op === '|!==') {
keep = first ? (attrs[field] !== val) : keep || (attrs[field] !== val);
} else if (op === '|>') {
keep = first ? (attrs[field] > val) : keep || (attrs[field] > val);
} else if (op === '|>=') {
keep = first ? (attrs[field] >= val) : keep || (attrs[field] >= val);
} else if (op === '|<') {
keep = first ? (attrs[field] < val) : keep || (attrs[field] < val);
} else if (op === '|<=') {
keep = first ? (attrs[field] <= val) : keep || (attrs[field] <= val);
} else if (op === '|in') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) !== -1 : keep || val.indexOf(attrs[field]) !== -1;
} else if (op === 'contains') {
if (DSUtils.isString(term)) {
expr = (val || '').indexOf(term) !== -1;
} else {
keep = first ? DSUtils.contains(val, attrs[field]) : keep || DSUtils.contains(val, attrs[field]);
expr = DSUtils.contains(val, term);
}
} else if (op === '|notIn') {
if (DSUtils.isString(val)) {
keep = first ? val.indexOf(attrs[field]) === -1 : keep || val.indexOf(attrs[field]) === -1;
} else if (op === 'notContains') {
if (DSUtils.isString(term)) {
expr = (val || '').indexOf(term) === -1;
} else {
keep = first ? !DSUtils.contains(val, attrs[field]) : keep || !DSUtils.contains(val, attrs[field]);
expr = !DSUtils.contains(val, term);
}
}
if (expr !== undefined) {
keep = first ? expr : (isOr ? keep || expr : keep && expr);
}
first = false;
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/datastore/sync_methods/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,9 @@ function _inject(definition, resource, attrs, options) {
} else {
item = {};
}
resource.previousAttributes[id] = {};
resource.previousAttributes[id] = angular.copy(attrs);

DSUtils.deepMixIn(item, attrs);
DSUtils.deepMixIn(resource.previousAttributes[id], attrs);

resource.collection.push(item);

Expand Down
7 changes: 5 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var toPromisify = [

var find = require('mout/array/find');
var isRegExp = require('mout/lang/isRegExp');
var deepEquals = angular.equals;

function isBlacklisted(prop, blacklist) {
if (!blacklist || !blacklist.length) {
Expand Down Expand Up @@ -87,6 +88,7 @@ module.exports = ['$q', function ($q) {
upperCase: require('mout/string/upperCase'),
pascalCase: require('mout/string/pascalCase'),
deepMixIn: require('mout/object/deepMixIn'),
deepEquals: deepEquals,
mixIn: require('mout/object/mixIn'),
forEach: angular.forEach,
pick: require('mout/object/pick'),
Expand All @@ -100,6 +102,7 @@ module.exports = ['$q', function ($q) {
slice: require('mout/array/slice'),
sort: require('mout/array/sort'),
guid: require('mout/random/guid'),
copy: angular.copy,
keys: require('mout/object/keys'),
_: function (parent, options) {
var _this = this;
Expand Down Expand Up @@ -174,7 +177,7 @@ module.exports = ['$q', function ($q) {
continue;
}

if (newValue !== undefined && newValue === oldObject[prop]) {
if (newValue !== undefined && deepEquals(newValue, oldObject[prop])) {
continue;
}

Expand All @@ -183,7 +186,7 @@ module.exports = ['$q', function ($q) {
continue;
}

if (newValue !== oldObject[prop]) {
if (!deepEquals(newValue, oldObject[prop])) {
changed[prop] = newValue;
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/integration/datastore/sync_methods/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ describe('DS.filter(resourceName[, params][, options])', function () {

assert.deepEqual(JSON.stringify(DS.filter('post', params)), JSON.stringify([p2, p3, p4, p5]), 'should accept normal "notIn" clause with a string');

params.where = {
author: {
'contains': 'oh'
}
};

assert.deepEqual(JSON.stringify(DS.filter('post', params)), JSON.stringify([p1]), 'should accept normal "contains" clause with a string');

params.where = {
author: {
'notContains': 'oh'
}
};

assert.deepEqual(JSON.stringify(DS.filter('post', params)), JSON.stringify([p2, p3, p4, p5]), 'should accept normal "notContains" clause with a string');

params.where = {
age: {
'|in': [31]
Expand Down

0 comments on commit 2bb8fb7

Please sign in to comment.