Skip to content

Commit

Permalink
Fixes #88. Fixes #89.
Browse files Browse the repository at this point in the history
Stable Version 0.10.0-beta.2.
  • Loading branch information
jmdobry committed Jul 11, 2014
1 parent acffdef commit 12a029e
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 61 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
##### 0.10.0-beta.2 - xx July 2014
##### 0.10.0-beta.2 - 10 July 2014

###### Backwards compatible API changes
- #89 - Added the `cacheResponse` option to `DS.create` and `DS.save`

###### Backwards compatible bug fixes
- #87 - Filter where boolean values

###### Other
- #88 - Fixed guide documentation for the simple default `where` filter

##### 0.10.0-beta.1 - 28 June 2014

###### Breaking API changes
Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);

var dev = process.cwd().indexOf('/home/jdobry/angular-data') === -1,
pkg = grunt.file.readJSON('package.json');
var dev = process.cwd().indexOf('/home/jdobry/angular-data') === -1;
var pkg = grunt.file.readJSON('package.json');

// Project configuration.
grunt.initConfig({
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
__Data store for Angular.js.__

__Latest Release:__ [0.9.1](http://angular-data.pseudobry.com/)
__master:__ [0.9.1](http://angular-data-next.pseudobry.com/)
__master:__ [0.10.0-beta.2](http://angular-data-next.pseudobry.com/)

Angular-data is in a pre-1.0.0 development stage; the API is fluctuating, not a lot of tests yet, etc.
Angular-data is approaching 1.0.0 Beta. The API is stabilizing and angular-data is well tested.

Not for production use (yet). If you still want to develop with Angular-data, be prepared to keep a close eye on the changelog, as the API is still liable to change before 1.0.0.
Angular-data is being used in production, though it's not 1.0.0. If you want to use Angular-data, keep an eye on the changelog. 1.0.0 will introduce strict semver (minor number is bumped for breaking changes right now).

Roadmap:
- Relations/Associations
- Various Adapters
- Schema Definition/Validation
- Even more adapters
- Nested Resources
- See [issues](https://github.com/jmdobry/angular-data/issues?milestone=7&page=1&state=open) for what's in development
- See [issues](https://github.com/jmdobry/angular-data/issues?page=1&state=open) for what's in development
- See [Design Doc](https://docs.google.com/document/d/1o069KLuBH4jpwm1FCLZFwKMgM73Xi8_1JyjhSxVpidM/edit?usp=sharing) for other juicy reading material

## Changelog
[CHANGELOG.md](https://github.com/jmdobry/angular-data/blob/master/CHANGELOG.md)

## Version Migration
[TRANSITION.md](https://github.com/jmdobry/angular-data/blob/master/TRANSITION.md)

## Resources

#### Community
Expand Down
57 changes: 37 additions & 20 deletions dist/angular-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,10 @@ var errorPrefix = 'DS.create(resourceName, attrs[, options]): ';
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {object} attrs The attributes with which to update the item of the type specified by `resourceName` that has
* the primary key specified by `id`.
* @param {object=} options Configuration options.
* @param {object=} options Configuration options. Properties:
*
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
* @returns {Promise} Promise produced by the `$q` service.
*
* ## Resolves with:
Expand Down Expand Up @@ -1882,6 +1885,10 @@ function create(resourceName, attrs, options) {
var resource = this.store[resourceName];
var _this = this;

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
}

promise = promise
.then(function (attrs) {
return _this.$q.promisify(definition.beforeValidate)(resourceName, attrs);
Expand All @@ -1902,11 +1909,15 @@ function create(resourceName, attrs, options) {
return _this.$q.promisify(definition.afterCreate)(resourceName, definition.deserialize(resourceName, res));
})
.then(function (data) {
var created = _this.inject(definition.name, data);
var id = created[definition.idAttribute];
resource.previousAttributes[id] = _this.utils.deepMixIn({}, created);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(definition.name, id);
if (options.cacheResponse) {
var created = _this.inject(definition.name, data);
var id = created[definition.idAttribute];
resource.previousAttributes[id] = _this.utils.deepMixIn({}, created);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(definition.name, id);
} else {
return data;
}
});

deferred.resolve(attrs);
Expand Down Expand Up @@ -2133,6 +2144,7 @@ var errorPrefix = 'DS.find(resourceName, id[, options]): ';
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {string|number} id The primary key of the item to retrieve.
* @param {object=} options Optional configuration. Properties:
*
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
Expand Down Expand Up @@ -2166,8 +2178,6 @@ function find(resourceName, id, options) {

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
} else {
options.cacheResponse = !!options.cacheResponse;
}

var definition = this.definitions[resourceName];
Expand Down Expand Up @@ -2316,6 +2326,7 @@ function _findAll(utils, resourceName, params, options) {
* - `{string|array=}` - `orderBy` - OrderBy clause.
*
* @param {object=} options Optional configuration. Properties:
*
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
Expand Down Expand Up @@ -2351,8 +2362,6 @@ function findAll(resourceName, params, options) {

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
} else {
options.cacheResponse = !!options.cacheResponse;
}

promise = promise.then(function () {
Expand Down Expand Up @@ -2645,7 +2654,7 @@ var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
*
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {string|number} id The primary key of the item to refresh from the server.
* @param {object=} options Optional configuration. Properties:
* @param {object=} options Optional configuration passed through to `DS.find` if it is called.
* @returns {false|Promise} `false` if the item doesn't already exist in the data store. A `Promise` if the item does
* exist in the data store and is being refreshed.
*
Expand Down Expand Up @@ -2712,7 +2721,9 @@ var errorPrefix = 'DS.save(resourceName, id[, options]): ';
*
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {string|number} id The primary key of the item to retrieve.
* @param {object=} options Optional configuration. Properties:
* @param {object=} options Optional configuration. Properties::
*
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
* - `{boolean=}` - `changesOnly` - Only send changed and added values back to the server.
*
* @returns {Promise} Promise produced by the `$q` service.
Expand Down Expand Up @@ -2753,6 +2764,10 @@ function save(resourceName, id, options) {
var resource = this.store[resourceName];
var _this = this;

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
}

promise = promise
.then(function (attrs) {
return _this.$q.promisify(definition.beforeValidate)(resourceName, attrs);
Expand Down Expand Up @@ -2792,10 +2807,14 @@ function save(resourceName, id, options) {
return _this.$q.promisify(definition.afterUpdate)(resourceName, definition.deserialize(resourceName, res));
})
.then(function (data) {
_this.inject(definition.name, data, options);
resource.previousAttributes[id] = _this.utils.deepMixIn({}, data);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(resourceName, id);
if (options.cacheResponse) {
var saved = _this.inject(definition.name, data, options);
resource.previousAttributes[id] = _this.utils.deepMixIn({}, saved);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(resourceName, id);
} else {
return data;
}
});

deferred.resolve(item);
Expand Down Expand Up @@ -2842,6 +2861,7 @@ var errorPrefix = 'DS.update(resourceName, id, attrs[, options]): ';
* @param {string|number} id The primary key of the item to update.
* @param {object} attrs The attributes with which to update the item.
* @param {object=} options Optional configuration. Properties:
*
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
* @returns {Promise} Promise produced by the `$q` service.
Expand Down Expand Up @@ -2880,8 +2900,6 @@ function update(resourceName, id, attrs, options) {

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
} else {
options.cacheResponse = !!options.cacheResponse;
}

promise = promise
Expand Down Expand Up @@ -2973,6 +2991,7 @@ var errorPrefix = 'DS.updateAll(resourceName, attrs, params[, options]): ';
* - `{string|array=}` - `orderBy` - OrderBy clause.
*
* @param {object=} options Optional configuration. Properties:
*
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
* @returns {Promise} Promise produced by the `$q` service.
Expand Down Expand Up @@ -3010,8 +3029,6 @@ function updateAll(resourceName, attrs, params, options) {

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
} else {
options.cacheResponse = !!options.cacheResponse;
}

promise = promise
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-data.min.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions guide/angular-data/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ DS.filter('post', {

#### Shortcuts

These are equivalent:
###### `==` operator shortcut

The following are equivalent:
```js
DS.filter('post', {
author: 'John'
Expand All @@ -234,13 +236,15 @@ DS.filter('post', {
DS.filter('post', {
where: {
author: {
'in': ['John', 'Sally']
'==': 'John'
}
}
});
```

These are equivalent:
###### `orderBy` shortcut

The following are equivalent:
```js
DS.filter('post', {
orderBy: 'age'
Expand Down
23 changes: 17 additions & 6 deletions src/datastore/async_methods/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ var errorPrefix = 'DS.create(resourceName, attrs[, options]): ';
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {object} attrs The attributes with which to update the item of the type specified by `resourceName` that has
* the primary key specified by `id`.
* @param {object=} options Configuration options.
* @param {object=} options Configuration options. Properties:
*
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
* @returns {Promise} Promise produced by the `$q` service.
*
* ## Resolves with:
Expand Down Expand Up @@ -57,6 +60,10 @@ function create(resourceName, attrs, options) {
var resource = this.store[resourceName];
var _this = this;

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
}

promise = promise
.then(function (attrs) {
return _this.$q.promisify(definition.beforeValidate)(resourceName, attrs);
Expand All @@ -77,11 +84,15 @@ function create(resourceName, attrs, options) {
return _this.$q.promisify(definition.afterCreate)(resourceName, definition.deserialize(resourceName, res));
})
.then(function (data) {
var created = _this.inject(definition.name, data);
var id = created[definition.idAttribute];
resource.previousAttributes[id] = _this.utils.deepMixIn({}, created);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(definition.name, id);
if (options.cacheResponse) {
var created = _this.inject(definition.name, data);
var id = created[definition.idAttribute];
resource.previousAttributes[id] = _this.utils.deepMixIn({}, created);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(definition.name, id);
} else {
return data;
}
});

deferred.resolve(attrs);
Expand Down
3 changes: 1 addition & 2 deletions src/datastore/async_methods/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var errorPrefix = 'DS.find(resourceName, id[, options]): ';
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {string|number} id The primary key of the item to retrieve.
* @param {object=} options Optional configuration. Properties:
*
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
Expand Down Expand Up @@ -62,8 +63,6 @@ function find(resourceName, id, options) {

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
} else {
options.cacheResponse = !!options.cacheResponse;
}

var definition = this.definitions[resourceName];
Expand Down
3 changes: 1 addition & 2 deletions src/datastore/async_methods/findAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function _findAll(utils, resourceName, params, options) {
* - `{string|array=}` - `orderBy` - OrderBy clause.
*
* @param {object=} options Optional configuration. Properties:
*
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
Expand Down Expand Up @@ -138,8 +139,6 @@ function findAll(resourceName, params, options) {

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
} else {
options.cacheResponse = !!options.cacheResponse;
}

promise = promise.then(function () {
Expand Down
2 changes: 1 addition & 1 deletion src/datastore/async_methods/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
*
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {string|number} id The primary key of the item to refresh from the server.
* @param {object=} options Optional configuration. Properties:
* @param {object=} options Optional configuration passed through to `DS.find` if it is called.
* @returns {false|Promise} `false` if the item doesn't already exist in the data store. A `Promise` if the item does
* exist in the data store and is being refreshed.
*
Expand Down
20 changes: 15 additions & 5 deletions src/datastore/async_methods/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ var errorPrefix = 'DS.save(resourceName, id[, options]): ';
*
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
* @param {string|number} id The primary key of the item to retrieve.
* @param {object=} options Optional configuration. Properties:
* @param {object=} options Optional configuration. Properties::
*
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
* - `{boolean=}` - `changesOnly` - Only send changed and added values back to the server.
*
* @returns {Promise} Promise produced by the `$q` service.
Expand Down Expand Up @@ -68,6 +70,10 @@ function save(resourceName, id, options) {
var resource = this.store[resourceName];
var _this = this;

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
}

promise = promise
.then(function (attrs) {
return _this.$q.promisify(definition.beforeValidate)(resourceName, attrs);
Expand Down Expand Up @@ -107,10 +113,14 @@ function save(resourceName, id, options) {
return _this.$q.promisify(definition.afterUpdate)(resourceName, definition.deserialize(resourceName, res));
})
.then(function (data) {
_this.inject(definition.name, data, options);
resource.previousAttributes[id] = _this.utils.deepMixIn({}, data);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(resourceName, id);
if (options.cacheResponse) {
var saved = _this.inject(definition.name, data, options);
resource.previousAttributes[id] = _this.utils.deepMixIn({}, saved);
resource.saved[id] = _this.utils.updateTimestamp(resource.saved[id]);
return _this.get(resourceName, id);
} else {
return data;
}
});

deferred.resolve(item);
Expand Down
3 changes: 1 addition & 2 deletions src/datastore/async_methods/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var errorPrefix = 'DS.update(resourceName, id, attrs[, options]): ';
* @param {string|number} id The primary key of the item to update.
* @param {object} attrs The attributes with which to update the item.
* @param {object=} options Optional configuration. Properties:
*
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
*
* @returns {Promise} Promise produced by the `$q` service.
Expand Down Expand Up @@ -69,8 +70,6 @@ function update(resourceName, id, attrs, options) {

if (!('cacheResponse' in options)) {
options.cacheResponse = true;
} else {
options.cacheResponse = !!options.cacheResponse;
}

promise = promise
Expand Down
Loading

0 comments on commit 12a029e

Please sign in to comment.