Skip to content

0.9.1 #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
##### 0.9.1 - xx May 2014

###### Backwards compatible bug fixes
- #68 - Async methods should honor methods on a resource definition.
- #69 - Failed requests should throw an error, not just return it
- #70 - Make `params` and `params.query` optional

##### 0.9.0 - 22 May 2014

###### Breaking API changes
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

__Data store for Angular.js.__

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

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.9.0",
"version": "0.9.1",
"homepage": "http://angular-data.codetrain.io/",
"repository": {
"type": "git",
Expand Down
59 changes: 34 additions & 25 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 0.9.0 - Homepage <http://angular-data.codetrain.io/>
* @version 0.9.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>
*
Expand Down Expand Up @@ -1570,7 +1570,9 @@ function DSHttpAdapterProvider() {
options = options || {};
options.params = options.params || {};
if (params) {
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
if (params.query) {
params.query = defaults.queryTransform(resourceConfig.name, params.query);
}
DSUtils.deepMixIn(options.params, params);
}
return this.DEL(
Expand All @@ -1591,7 +1593,9 @@ function DSHttpAdapterProvider() {
options = options || {};
options.params = options.params || {};
if (params) {
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
if (params.query) {
params.query = defaults.queryTransform(resourceConfig.name, params.query);
}
DSUtils.deepMixIn(options.params, params);
}
return this.GET(
Expand All @@ -1613,7 +1617,9 @@ function DSHttpAdapterProvider() {
options = options || {};
options.params = options.params || {};
if (params) {
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
if (params.query) {
params.query = defaults.queryTransform(resourceConfig.name, params.query);
}
DSUtils.deepMixIn(options.params, params);
}
return this.PUT(
Expand Down Expand Up @@ -2182,7 +2188,7 @@ function find(resourceName, id, options) {
}
}, function (err) {
delete resource.pendingQueries[id];
return err;
return _this.$q.reject(err);
});
}

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

// Merge the new values into the cache
this.inject(resourceName, data);

// Update modified timestamp of collection
resource.collectionModified = utils.updateTimestamp(resource.collectionModified);
return data;

// Merge the new values into the cache
return this.inject(resourceName, data);
}

function _findAll(utils, resourceName, params, options) {
Expand All @@ -2243,14 +2248,14 @@ function _findAll(utils, resourceName, params, options) {
try {
return processResults.apply(_this, [utils, data, resourceName, queryHash]);
} catch (err) {
throw new _this.errors.UnhandledError(err);
return _this.$q.reject(_this.errors.UnhandledError(err));
}
} else {
return data;
}
}, function (err) {
delete resource.pendingQueries[queryHash];
return err;
return _this.$q.reject(err);
});
}

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

options = options || {};
params = params || {};

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

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

// Protect against null
params.query = params.query || {};
params = params || {};

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

Expand All @@ -4090,6 +4096,7 @@ function filter(resourceName, params, options) {
}
}

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

try {
// cache miss, request resource from server
var item = this.store[resourceName].index.get(id);
if (!item && options.loadFromServer) {
this.find(resourceName, id).then(null, function (err) {
throw err;
return _this.$q.reject(err);
});
}

Expand Down Expand Up @@ -4470,9 +4478,11 @@ function _inject(definition, resource, attrs) {
}
}

var injected;
if (_this.utils.isArray(attrs)) {
injected = [];
for (var i = 0; i < attrs.length; i++) {
_inject.call(_this, definition, resource, attrs[i]);
injected.push(_inject.call(_this, definition, resource, attrs[i]));
}
} else {
if (!(definition.idAttribute in attrs)) {
Expand Down Expand Up @@ -4517,12 +4527,14 @@ function _inject(definition, resource, attrs) {
}
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
definition.afterInject(definition.name, item);
injected = item;
} catch (err) {
$log.error(err);
$log.error('inject failed!', definition.name, attrs);
}
}
}
return injected;
}

/**
Expand Down Expand Up @@ -4586,18 +4598,15 @@ function inject(resourceName, attrs, options) {
_this = this;

try {
var injected;
if (!this.$rootScope.$$phase) {
this.$rootScope.$apply(function () {
_inject.apply(_this, [definition, resource, attrs]);
injected = _inject.apply(_this, [definition, resource, attrs]);
});
} else {
_inject.apply(_this, [definition, resource, attrs]);
}
if (_this.utils.isArray(attrs)) {
return attrs;
} else {
return this.get(resourceName, attrs[definition.idAttribute]);
injected = _inject.apply(_this, [definition, resource, attrs]);
}
return injected;
} catch (err) {
if (!(err instanceof this.errors.RuntimeError)) {
throw new this.errors.UnhandledError(err);
Expand Down Expand Up @@ -4963,7 +4972,7 @@ module.exports = [function () {
* @id angular-data
* @name angular-data
* @description
* __Version:__ 0.9.0
* __Version:__ 0.9.1
*
* ## Install
*
Expand Down
6 changes: 3 additions & 3 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 @@ -72,7 +72,7 @@
<i class="icon-wrench icon-white"></i> API <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li class="nav-header">Angular-data - 0.9.0</li>
<li class="nav-header">Angular-data - 0.9.1</li>
<li>
<a href="/documentation/api/angular-data/angular-data">Overview</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion 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.9.0",
"version": "0.9.1",
"homepage": "http://angular-data.codetrain.io",
"repository": {
"type": "git",
Expand Down
12 changes: 9 additions & 3 deletions src/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ function DSHttpAdapterProvider() {
options = options || {};
options.params = options.params || {};
if (params) {
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
if (params.query) {
params.query = defaults.queryTransform(resourceConfig.name, params.query);
}
DSUtils.deepMixIn(options.params, params);
}
return this.DEL(
Expand All @@ -390,7 +392,9 @@ function DSHttpAdapterProvider() {
options = options || {};
options.params = options.params || {};
if (params) {
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
if (params.query) {
params.query = defaults.queryTransform(resourceConfig.name, params.query);
}
DSUtils.deepMixIn(options.params, params);
}
return this.GET(
Expand All @@ -412,7 +416,9 @@ function DSHttpAdapterProvider() {
options = options || {};
options.params = options.params || {};
if (params) {
params.query = params.query ? defaults.queryTransform(resourceConfig.name, params.query) : params.query;
if (params.query) {
params.query = defaults.queryTransform(resourceConfig.name, params.query);
}
DSUtils.deepMixIn(options.params, params);
}
return this.PUT(
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/async_methods/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function find(resourceName, id, options) {
}
}, function (err) {
delete resource.pendingQueries[id];
return err;
return _this.$q.reject(err);
});
}

Expand Down
14 changes: 7 additions & 7 deletions src/datastore/async_methods/findAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ function processResults(utils, data, resourceName, queryHash) {
delete resource.pendingQueries[queryHash];
resource.completedQueries[queryHash] = new Date().getTime();

// Merge the new values into the cache
this.inject(resourceName, data);

// Update modified timestamp of collection
resource.collectionModified = utils.updateTimestamp(resource.collectionModified);
return data;

// Merge the new values into the cache
return this.inject(resourceName, data);
}

function _findAll(utils, resourceName, params, options) {
Expand All @@ -40,14 +39,14 @@ function _findAll(utils, resourceName, params, options) {
try {
return processResults.apply(_this, [utils, data, resourceName, queryHash]);
} catch (err) {
throw new _this.errors.UnhandledError(err);
return _this.$q.reject(_this.errors.UnhandledError(err));
}
} else {
return data;
}
}, function (err) {
delete resource.pendingQueries[queryHash];
return err;
return _this.$q.reject(err);
});
}

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

options = options || {};
params = params || {};

if (!this.definitions[resourceName]) {
deferred.reject(new this.errors.RuntimeError(errorPrefix + resourceName + ' is not a registered resource!'));
Expand Down
7 changes: 4 additions & 3 deletions src/datastore/sync_methods/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var errorPrefix = 'DS.filter(resourceName, params[, options]): ';
* - `{UnhandledError}`
*
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {object} params Parameter object that is serialized into the query string. Properties:
* @param {object=} params Parameter object that is serialized into the query string. Properties:
*
* - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
* - `{object=}` - `where` - Where clause.
Expand All @@ -43,7 +43,7 @@ function filter(resourceName, params, options) {

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

// Protect against null
params.query = params.query || {};
params = params || {};

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

Expand All @@ -68,6 +68,7 @@ function filter(resourceName, params, options) {
}
}

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