Skip to content

Commit 82148bd

Browse files
committed
Merge pull request #71 from jmdobry/0.9.1
0.9.1
2 parents 4099670 + 679426e commit 82148bd

File tree

19 files changed

+187
-76
lines changed

19 files changed

+187
-76
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
##### 0.9.1 - xx May 2014
2+
3+
###### Backwards compatible bug fixes
4+
- #68 - Async methods should honor methods on a resource definition.
5+
- #69 - Failed requests should throw an error, not just return it
6+
- #70 - Make `params` and `params.query` optional
7+
18
##### 0.9.0 - 22 May 2014
29

310
###### Breaking API changes

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
__Data store for Angular.js.__
44

5-
__Latest Release:__ [0.8.1](http://angular-data.codetrain.io/)
6-
__master:__ [0.9.0](http://angular-data-next.codetrain.io/)
5+
__Latest Release:__ [0.9.1](http://angular-data.codetrain.io/)
6+
__master:__ [0.9.1](http://angular-data-next.codetrain.io/)
77

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

Diff for: 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.9.0",
5+
"version": "0.9.1",
66
"homepage": "http://angular-data.codetrain.io/",
77
"repository": {
88
"type": "git",

Diff for: dist/angular-data.js

+34-25
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 0.9.0 - Homepage <http://angular-data.codetrain.io/>
4+
* @version 0.9.1 - Homepage <http://angular-data.codetrain.io/>
55
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
66
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77
*
@@ -1570,7 +1570,9 @@ function DSHttpAdapterProvider() {
15701570
options = options || {};
15711571
options.params = options.params || {};
15721572
if (params) {
1573-
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
1573+
if (params.query) {
1574+
params.query = defaults.queryTransform(resourceConfig.name, params.query);
1575+
}
15741576
DSUtils.deepMixIn(options.params, params);
15751577
}
15761578
return this.DEL(
@@ -1591,7 +1593,9 @@ function DSHttpAdapterProvider() {
15911593
options = options || {};
15921594
options.params = options.params || {};
15931595
if (params) {
1594-
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
1596+
if (params.query) {
1597+
params.query = defaults.queryTransform(resourceConfig.name, params.query);
1598+
}
15951599
DSUtils.deepMixIn(options.params, params);
15961600
}
15971601
return this.GET(
@@ -1613,7 +1617,9 @@ function DSHttpAdapterProvider() {
16131617
options = options || {};
16141618
options.params = options.params || {};
16151619
if (params) {
1616-
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
1620+
if (params.query) {
1621+
params.query = defaults.queryTransform(resourceConfig.name, params.query);
1622+
}
16171623
DSUtils.deepMixIn(options.params, params);
16181624
}
16191625
return this.PUT(
@@ -2182,7 +2188,7 @@ function find(resourceName, id, options) {
21822188
}
21832189
}, function (err) {
21842190
delete resource.pendingQueries[id];
2185-
return err;
2191+
return _this.$q.reject(err);
21862192
});
21872193
}
21882194

@@ -2212,12 +2218,11 @@ function processResults(utils, data, resourceName, queryHash) {
22122218
delete resource.pendingQueries[queryHash];
22132219
resource.completedQueries[queryHash] = new Date().getTime();
22142220

2215-
// Merge the new values into the cache
2216-
this.inject(resourceName, data);
2217-
22182221
// Update modified timestamp of collection
22192222
resource.collectionModified = utils.updateTimestamp(resource.collectionModified);
2220-
return data;
2223+
2224+
// Merge the new values into the cache
2225+
return this.inject(resourceName, data);
22212226
}
22222227

22232228
function _findAll(utils, resourceName, params, options) {
@@ -2243,14 +2248,14 @@ function _findAll(utils, resourceName, params, options) {
22432248
try {
22442249
return processResults.apply(_this, [utils, data, resourceName, queryHash]);
22452250
} catch (err) {
2246-
throw new _this.errors.UnhandledError(err);
2251+
return _this.$q.reject(_this.errors.UnhandledError(err));
22472252
}
22482253
} else {
22492254
return data;
22502255
}
22512256
}, function (err) {
22522257
delete resource.pendingQueries[queryHash];
2253-
return err;
2258+
return _this.$q.reject(err);
22542259
});
22552260
}
22562261

@@ -2302,7 +2307,7 @@ function _findAll(utils, resourceName, params, options) {
23022307
* ```
23032308
*
23042309
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
2305-
* @param {object} params Parameter object that is serialized into the query string. Properties:
2310+
* @param {object=} params Parameter object that is serialized into the query string. Properties:
23062311
*
23072312
* - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
23082313
* - `{object=}` - `where` - Where clause.
@@ -2332,6 +2337,7 @@ function findAll(resourceName, params, options) {
23322337
_this = this;
23332338

23342339
options = options || {};
2340+
params = params || {};
23352341

23362342
if (!this.definitions[resourceName]) {
23372343
deferred.reject(new this.errors.RuntimeError(errorPrefix + resourceName + ' is not a registered resource!'));
@@ -4048,7 +4054,7 @@ var errorPrefix = 'DS.filter(resourceName, params[, options]): ';
40484054
* - `{UnhandledError}`
40494055
*
40504056
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
4051-
* @param {object} params Parameter object that is serialized into the query string. Properties:
4057+
* @param {object=} params Parameter object that is serialized into the query string. Properties:
40524058
*
40534059
* - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
40544060
* - `{object=}` - `where` - Where clause.
@@ -4065,7 +4071,7 @@ function filter(resourceName, params, options) {
40654071

40664072
if (!this.definitions[resourceName]) {
40674073
throw new this.errors.RuntimeError(errorPrefix + resourceName + ' is not a registered resource!');
4068-
} else if (!this.utils.isObject(params)) {
4074+
} else if (params && !this.utils.isObject(params)) {
40694075
throw new this.errors.IllegalArgumentError(errorPrefix + 'params: Must be an object!', { params: { actual: typeof params, expected: 'object' } });
40704076
} else if (!this.utils.isObject(options)) {
40714077
throw new this.errors.IllegalArgumentError(errorPrefix + 'options: Must be an object!', { options: { actual: typeof options, expected: 'object' } });
@@ -4077,7 +4083,7 @@ function filter(resourceName, params, options) {
40774083
_this = this;
40784084

40794085
// Protect against null
4080-
params.query = params.query || {};
4086+
params = params || {};
40814087

40824088
var queryHash = this.utils.toJson(params);
40834089

@@ -4090,6 +4096,7 @@ function filter(resourceName, params, options) {
40904096
}
40914097
}
40924098

4099+
params.query = params.query || {};
40934100
// The query has been completed, so hit the cache with the query
40944101
var filtered = this.utils.filter(resource.collection, function (attrs) {
40954102
var keep = true,
@@ -4220,13 +4227,14 @@ function get(resourceName, id, options) {
42204227
} else if (!this.utils.isObject(options)) {
42214228
throw new this.errors.IllegalArgumentError(errorPrefix + 'options: Must be an object!', { options: { actual: typeof options, expected: 'object' } });
42224229
}
4230+
var _this = this;
42234231

42244232
try {
42254233
// cache miss, request resource from server
42264234
var item = this.store[resourceName].index.get(id);
42274235
if (!item && options.loadFromServer) {
42284236
this.find(resourceName, id).then(null, function (err) {
4229-
throw err;
4237+
return _this.$q.reject(err);
42304238
});
42314239
}
42324240

@@ -4470,9 +4478,11 @@ function _inject(definition, resource, attrs) {
44704478
}
44714479
}
44724480

4481+
var injected;
44734482
if (_this.utils.isArray(attrs)) {
4483+
injected = [];
44744484
for (var i = 0; i < attrs.length; i++) {
4475-
_inject.call(_this, definition, resource, attrs[i]);
4485+
injected.push(_inject.call(_this, definition, resource, attrs[i]));
44764486
}
44774487
} else {
44784488
if (!(definition.idAttribute in attrs)) {
@@ -4517,12 +4527,14 @@ function _inject(definition, resource, attrs) {
45174527
}
45184528
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
45194529
definition.afterInject(definition.name, item);
4530+
injected = item;
45204531
} catch (err) {
45214532
$log.error(err);
45224533
$log.error('inject failed!', definition.name, attrs);
45234534
}
45244535
}
45254536
}
4537+
return injected;
45264538
}
45274539

45284540
/**
@@ -4586,18 +4598,15 @@ function inject(resourceName, attrs, options) {
45864598
_this = this;
45874599

45884600
try {
4601+
var injected;
45894602
if (!this.$rootScope.$$phase) {
45904603
this.$rootScope.$apply(function () {
4591-
_inject.apply(_this, [definition, resource, attrs]);
4604+
injected = _inject.apply(_this, [definition, resource, attrs]);
45924605
});
45934606
} else {
4594-
_inject.apply(_this, [definition, resource, attrs]);
4595-
}
4596-
if (_this.utils.isArray(attrs)) {
4597-
return attrs;
4598-
} else {
4599-
return this.get(resourceName, attrs[definition.idAttribute]);
4607+
injected = _inject.apply(_this, [definition, resource, attrs]);
46004608
}
4609+
return injected;
46014610
} catch (err) {
46024611
if (!(err instanceof this.errors.RuntimeError)) {
46034612
throw new this.errors.UnhandledError(err);
@@ -4963,7 +4972,7 @@ module.exports = [function () {
49634972
* @id angular-data
49644973
* @name angular-data
49654974
* @description
4966-
* __Version:__ 0.9.0
4975+
* __Version:__ 0.9.1
49674976
*
49684977
* ## Install
49694978
*

Diff for: dist/angular-data.min.js

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

Diff for: guide/nav.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<i class="icon-wrench icon-white"></i> API <b class="caret"></b>
7373
</a>
7474
<ul class="dropdown-menu">
75-
<li class="nav-header">Angular-data - 0.9.0</li>
75+
<li class="nav-header">Angular-data - 0.9.1</li>
7676
<li>
7777
<a href="/documentation/api/angular-data/angular-data">Overview</a>
7878
</li>

Diff for: package.json

+1-1
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.9.0",
4+
"version": "0.9.1",
55
"homepage": "http://angular-data.codetrain.io",
66
"repository": {
77
"type": "git",

Diff for: src/adapters/http.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,9 @@ function DSHttpAdapterProvider() {
369369
options = options || {};
370370
options.params = options.params || {};
371371
if (params) {
372-
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
372+
if (params.query) {
373+
params.query = defaults.queryTransform(resourceConfig.name, params.query);
374+
}
373375
DSUtils.deepMixIn(options.params, params);
374376
}
375377
return this.DEL(
@@ -390,7 +392,9 @@ function DSHttpAdapterProvider() {
390392
options = options || {};
391393
options.params = options.params || {};
392394
if (params) {
393-
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
395+
if (params.query) {
396+
params.query = defaults.queryTransform(resourceConfig.name, params.query);
397+
}
394398
DSUtils.deepMixIn(options.params, params);
395399
}
396400
return this.GET(
@@ -412,7 +416,9 @@ function DSHttpAdapterProvider() {
412416
options = options || {};
413417
options.params = options.params || {};
414418
if (params) {
415-
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
419+
if (params.query) {
420+
params.query = defaults.queryTransform(resourceConfig.name, params.query);
421+
}
416422
DSUtils.deepMixIn(options.params, params);
417423
}
418424
return this.PUT(

Diff for: src/datastore/async_methods/find.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function find(resourceName, id, options) {
8686
}
8787
}, function (err) {
8888
delete resource.pendingQueries[id];
89-
return err;
89+
return _this.$q.reject(err);
9090
});
9191
}
9292

Diff for: src/datastore/async_methods/findAll.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ function processResults(utils, data, resourceName, queryHash) {
99
delete resource.pendingQueries[queryHash];
1010
resource.completedQueries[queryHash] = new Date().getTime();
1111

12-
// Merge the new values into the cache
13-
this.inject(resourceName, data);
14-
1512
// Update modified timestamp of collection
1613
resource.collectionModified = utils.updateTimestamp(resource.collectionModified);
17-
return data;
14+
15+
// Merge the new values into the cache
16+
return this.inject(resourceName, data);
1817
}
1918

2019
function _findAll(utils, resourceName, params, options) {
@@ -40,14 +39,14 @@ function _findAll(utils, resourceName, params, options) {
4039
try {
4140
return processResults.apply(_this, [utils, data, resourceName, queryHash]);
4241
} catch (err) {
43-
throw new _this.errors.UnhandledError(err);
42+
return _this.$q.reject(_this.errors.UnhandledError(err));
4443
}
4544
} else {
4645
return data;
4746
}
4847
}, function (err) {
4948
delete resource.pendingQueries[queryHash];
50-
return err;
49+
return _this.$q.reject(err);
5150
});
5251
}
5352

@@ -99,7 +98,7 @@ function _findAll(utils, resourceName, params, options) {
9998
* ```
10099
*
101100
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
102-
* @param {object} params Parameter object that is serialized into the query string. Properties:
101+
* @param {object=} params Parameter object that is serialized into the query string. Properties:
103102
*
104103
* - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
105104
* - `{object=}` - `where` - Where clause.
@@ -129,6 +128,7 @@ function findAll(resourceName, params, options) {
129128
_this = this;
130129

131130
options = options || {};
131+
params = params || {};
132132

133133
if (!this.definitions[resourceName]) {
134134
deferred.reject(new this.errors.RuntimeError(errorPrefix + resourceName + ' is not a registered resource!'));

Diff for: src/datastore/sync_methods/filter.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var errorPrefix = 'DS.filter(resourceName, params[, options]): ';
2626
* - `{UnhandledError}`
2727
*
2828
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
29-
* @param {object} params Parameter object that is serialized into the query string. Properties:
29+
* @param {object=} params Parameter object that is serialized into the query string. Properties:
3030
*
3131
* - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
3232
* - `{object=}` - `where` - Where clause.
@@ -43,7 +43,7 @@ function filter(resourceName, params, options) {
4343

4444
if (!this.definitions[resourceName]) {
4545
throw new this.errors.RuntimeError(errorPrefix + resourceName + ' is not a registered resource!');
46-
} else if (!this.utils.isObject(params)) {
46+
} else if (params && !this.utils.isObject(params)) {
4747
throw new this.errors.IllegalArgumentError(errorPrefix + 'params: Must be an object!', { params: { actual: typeof params, expected: 'object' } });
4848
} else if (!this.utils.isObject(options)) {
4949
throw new this.errors.IllegalArgumentError(errorPrefix + 'options: Must be an object!', { options: { actual: typeof options, expected: 'object' } });
@@ -55,7 +55,7 @@ function filter(resourceName, params, options) {
5555
_this = this;
5656

5757
// Protect against null
58-
params.query = params.query || {};
58+
params = params || {};
5959

6060
var queryHash = this.utils.toJson(params);
6161

@@ -68,6 +68,7 @@ function filter(resourceName, params, options) {
6868
}
6969
}
7070

71+
params.query = params.query || {};
7172
// The query has been completed, so hit the cache with the query
7273
var filtered = this.utils.filter(resource.collection, function (attrs) {
7374
var keep = true,

0 commit comments

Comments
 (0)