Skip to content

Commit 2bb8fb7

Browse files
committed
Fixes #258 Fixes #259
Stable Version 1.5.1.
1 parent 7ecf97d commit 2bb8fb7

File tree

11 files changed

+107
-97
lines changed

11 files changed

+107
-97
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
##### 1.5.1 - 02 December 2014
2+
3+
###### Backwards compatible API changes
4+
- #259 - Added the "contains", "notContains", "|contains", and "|notContains" operators
5+
6+
###### Backwards compatible bug fixes
7+
- #258 - No changes detected on nested fields
8+
19
##### 1.5.0 - 01 December 2014
210

311
###### Backwards compatible API changes

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Unlike Backbone and Ember Models, angular-data does not require the use of gette
88

99
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.
1010

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

1313
Angular-data is finally 1.0.!
1414

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": "1.5.0",
5+
"version": "1.5.1",
66
"homepage": "http://angular-data.pseudobry.com/",
77
"repository": {
88
"type": "git",

dist/angular-data.js

+38-45
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @author Jason Dobry <[email protected]>
33
* @file angular-data.js
4-
* @version 1.5.0 - Homepage <http://angular-data.pseudobry.com/>
4+
* @version 1.5.1 - Homepage <http://angular-data.pseudobry.com/>
55
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
66
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77
*
@@ -988,7 +988,7 @@ var mixIn = require('../object/mixIn');
988988
var flags = '';
989989
flags += r.multiline ? 'm' : '';
990990
flags += r.global ? 'g' : '';
991-
flags += r.ignorecase ? 'i' : '';
991+
flags += r.ignoreCase ? 'i' : '';
992992
return new RegExp(r.source, flags);
993993
}
994994

@@ -4258,64 +4258,55 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42584258
};
42594259
}
42604260
if (DSUtils.isObject(clause)) {
4261-
DSUtils.forEach(clause, function (val, op) {
4261+
DSUtils.forEach(clause, function (term, op) {
4262+
var expr;
4263+
var isOr = op[0] === '|';
4264+
var val = attrs[field];
4265+
op = isOr ? op.substr(1) : op;
42624266
if (op === '==') {
4263-
keep = first ? (attrs[field] == val) : keep && (attrs[field] == val);
4267+
expr = val == term;
42644268
} else if (op === '===') {
4265-
keep = first ? (attrs[field] === val) : keep && (attrs[field] === val);
4269+
expr = val === term;
42664270
} else if (op === '!=') {
4267-
keep = first ? (attrs[field] != val) : keep && (attrs[field] != val);
4271+
expr = val != term;
42684272
} else if (op === '!==') {
4269-
keep = first ? (attrs[field] !== val) : keep && (attrs[field] !== val);
4273+
expr = val !== term;
42704274
} else if (op === '>') {
4271-
keep = first ? (attrs[field] > val) : keep && (attrs[field] > val);
4275+
expr = val > term;
42724276
} else if (op === '>=') {
4273-
keep = first ? (attrs[field] >= val) : keep && (attrs[field] >= val);
4277+
expr = val >= term;
42744278
} else if (op === '<') {
4275-
keep = first ? (attrs[field] < val) : keep && (attrs[field] < val);
4279+
expr = val < term;
42764280
} else if (op === '<=') {
4277-
keep = first ? (attrs[field] <= val) : keep && (attrs[field] <= val);
4281+
expr = val <= term;
42784282
} else if (op === 'in') {
4279-
if (DSUtils.isString(val)) {
4280-
keep = first ? val.indexOf(attrs[field]) !== -1 : keep && val.indexOf(attrs[field]) !== -1;
4283+
if (DSUtils.isString(term)) {
4284+
expr = term.indexOf(val) !== -1;
42814285
} else {
4282-
keep = first ? DSUtils.contains(val, attrs[field]) : keep && DSUtils.contains(val, attrs[field]);
4286+
expr = DSUtils.contains(term, val);
42834287
}
42844288
} else if (op === 'notIn') {
4285-
if (DSUtils.isString(val)) {
4286-
keep = first ? val.indexOf(attrs[field]) === -1 : keep && val.indexOf(attrs[field]) === -1;
4289+
if (DSUtils.isString(term)) {
4290+
expr = term.indexOf(val) === -1;
42874291
} else {
4288-
keep = first ? !DSUtils.contains(val, attrs[field]) : keep && !DSUtils.contains(val, attrs[field]);
4292+
expr = !DSUtils.contains(term, val);
42894293
}
4290-
} else if (op === '|==') {
4291-
keep = first ? (attrs[field] == val) : keep || (attrs[field] == val);
4292-
} else if (op === '|===') {
4293-
keep = first ? (attrs[field] === val) : keep || (attrs[field] === val);
4294-
} else if (op === '|!=') {
4295-
keep = first ? (attrs[field] != val) : keep || (attrs[field] != val);
4296-
} else if (op === '|!==') {
4297-
keep = first ? (attrs[field] !== val) : keep || (attrs[field] !== val);
4298-
} else if (op === '|>') {
4299-
keep = first ? (attrs[field] > val) : keep || (attrs[field] > val);
4300-
} else if (op === '|>=') {
4301-
keep = first ? (attrs[field] >= val) : keep || (attrs[field] >= val);
4302-
} else if (op === '|<') {
4303-
keep = first ? (attrs[field] < val) : keep || (attrs[field] < val);
4304-
} else if (op === '|<=') {
4305-
keep = first ? (attrs[field] <= val) : keep || (attrs[field] <= val);
4306-
} else if (op === '|in') {
4307-
if (DSUtils.isString(val)) {
4308-
keep = first ? val.indexOf(attrs[field]) !== -1 : keep || val.indexOf(attrs[field]) !== -1;
4294+
} else if (op === 'contains') {
4295+
if (DSUtils.isString(term)) {
4296+
expr = (val || '').indexOf(term) !== -1;
43094297
} else {
4310-
keep = first ? DSUtils.contains(val, attrs[field]) : keep || DSUtils.contains(val, attrs[field]);
4298+
expr = DSUtils.contains(val, term);
43114299
}
4312-
} else if (op === '|notIn') {
4313-
if (DSUtils.isString(val)) {
4314-
keep = first ? val.indexOf(attrs[field]) === -1 : keep || val.indexOf(attrs[field]) === -1;
4300+
} else if (op === 'notContains') {
4301+
if (DSUtils.isString(term)) {
4302+
expr = (val || '').indexOf(term) === -1;
43154303
} else {
4316-
keep = first ? !DSUtils.contains(val, attrs[field]) : keep || !DSUtils.contains(val, attrs[field]);
4304+
expr = !DSUtils.contains(val, term);
43174305
}
43184306
}
4307+
if (expr !== undefined) {
4308+
keep = first ? expr : (isOr ? keep || expr : keep && expr);
4309+
}
43194310
first = false;
43204311
});
43214312
}
@@ -6769,10 +6760,9 @@ function _inject(definition, resource, attrs, options) {
67696760
} else {
67706761
item = {};
67716762
}
6772-
resource.previousAttributes[id] = {};
6763+
resource.previousAttributes[id] = angular.copy(attrs);
67736764

67746765
DSUtils.deepMixIn(item, attrs);
6775-
DSUtils.deepMixIn(resource.previousAttributes[id], attrs);
67766766

67776767
resource.collection.push(item);
67786768

@@ -7824,6 +7814,7 @@ var toPromisify = [
78247814

78257815
var find = require('mout/array/find');
78267816
var isRegExp = require('mout/lang/isRegExp');
7817+
var deepEquals = angular.equals;
78277818

78287819
function isBlacklisted(prop, blacklist) {
78297820
if (!blacklist || !blacklist.length) {
@@ -7853,6 +7844,7 @@ module.exports = ['$q', function ($q) {
78537844
upperCase: require('mout/string/upperCase'),
78547845
pascalCase: require('mout/string/pascalCase'),
78557846
deepMixIn: require('mout/object/deepMixIn'),
7847+
deepEquals: deepEquals,
78567848
mixIn: require('mout/object/mixIn'),
78577849
forEach: angular.forEach,
78587850
pick: require('mout/object/pick'),
@@ -7866,6 +7858,7 @@ module.exports = ['$q', function ($q) {
78667858
slice: require('mout/array/slice'),
78677859
sort: require('mout/array/sort'),
78687860
guid: require('mout/random/guid'),
7861+
copy: angular.copy,
78697862
keys: require('mout/object/keys'),
78707863
_: function (parent, options) {
78717864
var _this = this;
@@ -7940,7 +7933,7 @@ module.exports = ['$q', function ($q) {
79407933
continue;
79417934
}
79427935

7943-
if (newValue !== undefined && newValue === oldObject[prop]) {
7936+
if (newValue !== undefined && deepEquals(newValue, oldObject[prop])) {
79447937
continue;
79457938
}
79467939

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

7952-
if (newValue !== oldObject[prop]) {
7945+
if (!deepEquals(newValue, oldObject[prop])) {
79537946
changed[prop] = newValue;
79547947
}
79557948
}

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.

guide/nav.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<i class="icon-wrench icon-white"></i> API <b class="caret"></b>
8383
</a>
8484
<ul class="dropdown-menu">
85-
<li class="nav-header">Angular-data - 1.5.0</li>
85+
<li class="nav-header">Angular-data - 1.5.1</li>
8686
<li>
8787
<a href="/documentation/api/angular-data/angular-data">Overview</a>
8888
</li>

package.json

+2-2
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": "1.5.0",
4+
"version": "1.5.1",
55
"homepage": "http://angular-data.pseudobry.com",
66
"repository": {
77
"type": "git",
@@ -47,6 +47,6 @@
4747
"test": "grunt test"
4848
},
4949
"dependencies": {
50-
"mout": "0.10.0"
50+
"mout": "0.11.0"
5151
}
5252
}

src/datastore/index.js

+30-39
Original file line numberDiff line numberDiff line change
@@ -96,64 +96,55 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
9696
};
9797
}
9898
if (DSUtils.isObject(clause)) {
99-
DSUtils.forEach(clause, function (val, op) {
99+
DSUtils.forEach(clause, function (term, op) {
100+
var expr;
101+
var isOr = op[0] === '|';
102+
var val = attrs[field];
103+
op = isOr ? op.substr(1) : op;
100104
if (op === '==') {
101-
keep = first ? (attrs[field] == val) : keep && (attrs[field] == val);
105+
expr = val == term;
102106
} else if (op === '===') {
103-
keep = first ? (attrs[field] === val) : keep && (attrs[field] === val);
107+
expr = val === term;
104108
} else if (op === '!=') {
105-
keep = first ? (attrs[field] != val) : keep && (attrs[field] != val);
109+
expr = val != term;
106110
} else if (op === '!==') {
107-
keep = first ? (attrs[field] !== val) : keep && (attrs[field] !== val);
111+
expr = val !== term;
108112
} else if (op === '>') {
109-
keep = first ? (attrs[field] > val) : keep && (attrs[field] > val);
113+
expr = val > term;
110114
} else if (op === '>=') {
111-
keep = first ? (attrs[field] >= val) : keep && (attrs[field] >= val);
115+
expr = val >= term;
112116
} else if (op === '<') {
113-
keep = first ? (attrs[field] < val) : keep && (attrs[field] < val);
117+
expr = val < term;
114118
} else if (op === '<=') {
115-
keep = first ? (attrs[field] <= val) : keep && (attrs[field] <= val);
119+
expr = val <= term;
116120
} else if (op === 'in') {
117-
if (DSUtils.isString(val)) {
118-
keep = first ? val.indexOf(attrs[field]) !== -1 : keep && val.indexOf(attrs[field]) !== -1;
121+
if (DSUtils.isString(term)) {
122+
expr = term.indexOf(val) !== -1;
119123
} else {
120-
keep = first ? DSUtils.contains(val, attrs[field]) : keep && DSUtils.contains(val, attrs[field]);
124+
expr = DSUtils.contains(term, val);
121125
}
122126
} else if (op === 'notIn') {
123-
if (DSUtils.isString(val)) {
124-
keep = first ? val.indexOf(attrs[field]) === -1 : keep && val.indexOf(attrs[field]) === -1;
127+
if (DSUtils.isString(term)) {
128+
expr = term.indexOf(val) === -1;
125129
} else {
126-
keep = first ? !DSUtils.contains(val, attrs[field]) : keep && !DSUtils.contains(val, attrs[field]);
130+
expr = !DSUtils.contains(term, val);
127131
}
128-
} else if (op === '|==') {
129-
keep = first ? (attrs[field] == val) : keep || (attrs[field] == val);
130-
} else if (op === '|===') {
131-
keep = first ? (attrs[field] === val) : keep || (attrs[field] === val);
132-
} else if (op === '|!=') {
133-
keep = first ? (attrs[field] != val) : keep || (attrs[field] != val);
134-
} else if (op === '|!==') {
135-
keep = first ? (attrs[field] !== val) : keep || (attrs[field] !== val);
136-
} else if (op === '|>') {
137-
keep = first ? (attrs[field] > val) : keep || (attrs[field] > val);
138-
} else if (op === '|>=') {
139-
keep = first ? (attrs[field] >= val) : keep || (attrs[field] >= val);
140-
} else if (op === '|<') {
141-
keep = first ? (attrs[field] < val) : keep || (attrs[field] < val);
142-
} else if (op === '|<=') {
143-
keep = first ? (attrs[field] <= val) : keep || (attrs[field] <= val);
144-
} else if (op === '|in') {
145-
if (DSUtils.isString(val)) {
146-
keep = first ? val.indexOf(attrs[field]) !== -1 : keep || val.indexOf(attrs[field]) !== -1;
132+
} else if (op === 'contains') {
133+
if (DSUtils.isString(term)) {
134+
expr = (val || '').indexOf(term) !== -1;
147135
} else {
148-
keep = first ? DSUtils.contains(val, attrs[field]) : keep || DSUtils.contains(val, attrs[field]);
136+
expr = DSUtils.contains(val, term);
149137
}
150-
} else if (op === '|notIn') {
151-
if (DSUtils.isString(val)) {
152-
keep = first ? val.indexOf(attrs[field]) === -1 : keep || val.indexOf(attrs[field]) === -1;
138+
} else if (op === 'notContains') {
139+
if (DSUtils.isString(term)) {
140+
expr = (val || '').indexOf(term) === -1;
153141
} else {
154-
keep = first ? !DSUtils.contains(val, attrs[field]) : keep || !DSUtils.contains(val, attrs[field]);
142+
expr = !DSUtils.contains(val, term);
155143
}
156144
}
145+
if (expr !== undefined) {
146+
keep = first ? expr : (isOr ? keep || expr : keep && expr);
147+
}
157148
first = false;
158149
});
159150
}

src/datastore/sync_methods/inject.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,9 @@ function _inject(definition, resource, attrs, options) {
149149
} else {
150150
item = {};
151151
}
152-
resource.previousAttributes[id] = {};
152+
resource.previousAttributes[id] = angular.copy(attrs);
153153

154154
DSUtils.deepMixIn(item, attrs);
155-
DSUtils.deepMixIn(resource.previousAttributes[id], attrs);
156155

157156
resource.collection.push(item);
158157

src/utils.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var toPromisify = [
5858

5959
var find = require('mout/array/find');
6060
var isRegExp = require('mout/lang/isRegExp');
61+
var deepEquals = angular.equals;
6162

6263
function isBlacklisted(prop, blacklist) {
6364
if (!blacklist || !blacklist.length) {
@@ -87,6 +88,7 @@ module.exports = ['$q', function ($q) {
8788
upperCase: require('mout/string/upperCase'),
8889
pascalCase: require('mout/string/pascalCase'),
8990
deepMixIn: require('mout/object/deepMixIn'),
91+
deepEquals: deepEquals,
9092
mixIn: require('mout/object/mixIn'),
9193
forEach: angular.forEach,
9294
pick: require('mout/object/pick'),
@@ -100,6 +102,7 @@ module.exports = ['$q', function ($q) {
100102
slice: require('mout/array/slice'),
101103
sort: require('mout/array/sort'),
102104
guid: require('mout/random/guid'),
105+
copy: angular.copy,
103106
keys: require('mout/object/keys'),
104107
_: function (parent, options) {
105108
var _this = this;
@@ -174,7 +177,7 @@ module.exports = ['$q', function ($q) {
174177
continue;
175178
}
176179

177-
if (newValue !== undefined && newValue === oldObject[prop]) {
180+
if (newValue !== undefined && deepEquals(newValue, oldObject[prop])) {
178181
continue;
179182
}
180183

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

186-
if (newValue !== oldObject[prop]) {
189+
if (!deepEquals(newValue, oldObject[prop])) {
187190
changed[prop] = newValue;
188191
}
189192
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ describe('DS.filter(resourceName[, params][, options])', function () {
200200

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

203+
params.where = {
204+
author: {
205+
'contains': 'oh'
206+
}
207+
};
208+
209+
assert.deepEqual(JSON.stringify(DS.filter('post', params)), JSON.stringify([p1]), 'should accept normal "contains" clause with a string');
210+
211+
params.where = {
212+
author: {
213+
'notContains': 'oh'
214+
}
215+
};
216+
217+
assert.deepEqual(JSON.stringify(DS.filter('post', params)), JSON.stringify([p2, p3, p4, p5]), 'should accept normal "notContains" clause with a string');
218+
203219
params.where = {
204220
age: {
205221
'|in': [31]

0 commit comments

Comments
 (0)