Skip to content

Commit b0f7421

Browse files
committed
Cleaned and corrected api documentation for the async DS methods. #124.
1 parent a97c769 commit b0f7421

12 files changed

+249
-253
lines changed

dist/angular-data.js

+126-128
Large diffs are not rendered by default.

dist/angular-data.min.js

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

src/datastore/async_methods/create.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function errorPrefix(resourceName) {
77
* @id DS.async_methods:create
88
* @name create
99
* @description
10-
* The "C" in "CRUD". Delegate to the `create` method of whatever adapter is being used (http by default) and inject the
10+
* The "C" in "CRUD". Delegate to the `create` method of whichever adapter is being used (http by default) and inject the
1111
* result into the data store.
1212
*
1313
* ## Signature:
@@ -32,7 +32,7 @@ function errorPrefix(resourceName) {
3232
* @param {object} attrs The attributes with which to create the item of the type specified by `resourceName`.
3333
* @param {object=} options Configuration options. Also passed along to the adapter's `create` method. Properties:
3434
*
35-
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
35+
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the adapter into the data store. Default: `true`.
3636
* - `{boolean=}` - `upsert` - If `attrs` already contains a primary key, then attempt to call `DS.update` instead. Default: `true`.
3737
*
3838
* @returns {Promise} Promise produced by the `$q` service.

src/datastore/async_methods/destroy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function errorPrefix(resourceName, id) {
77
* @id DS.async_methods:destroy
88
* @name destroy
99
* @description
10-
* The "D" in "CRUD". Delegate to the `destroy` method of whatever adapter is being used (http by default) eject the
10+
* The "D" in "CRUD". Delegate to the `destroy` method of whichever adapter is being used (http by default) and eject the
1111
* appropriate item from the data store.
1212
*
1313
* ## Signature:

src/datastore/async_methods/destroyAll.js

+16-20
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function errorPrefix(resourceName) {
77
* @id DS.async_methods:destroyAll
88
* @name destroyAll
99
* @description
10-
* Asynchronously return the resource from the server filtered by the query. The results will be added to the data
11-
* store when it returns from the server.
10+
* The "D" in "CRUD". Delegate to the `destroyAll` method of whichever adapter is being used (http by default) and eject
11+
* the appropriate items from the data store.
1212
*
1313
* ## Signature:
1414
* ```js
@@ -18,21 +18,18 @@ function errorPrefix(resourceName) {
1818
* ## Example:
1919
*
2020
* ```js
21-
* var params = {
22-
* where: {
23-
* author: {
24-
* '==': 'John Anderson'
25-
* }
26-
* }
27-
* };
21+
* var params = {
22+
* where: {
23+
* author: {
24+
* '==': 'John Anderson'
25+
* }
26+
* }
27+
* };
2828
*
29-
* DS.destroyAll('document', params).then(function (documents) {
30-
* // The documents are gone from the data store
31-
* DS.filter('document', params); // []
32-
*
33-
* }, function (err) {
34-
* // handle error
35-
* });
29+
* DS.destroyAll('document', params).then(function (documents) {
30+
* // The documents are gone from the data store
31+
* DS.filter('document', params); // []
32+
* });
3633
* ```
3734
*
3835
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
@@ -44,7 +41,7 @@ function errorPrefix(resourceName) {
4441
* - `{number=}` - `offset` - Same as skip.
4542
* - `{string|array=}` - `orderBy` - OrderBy clause.
4643
*
47-
* @param {object=} options Optional configuration. Properties:
44+
* @param {object=} options Optional configuration. Also passed along to the adapter's `destroyAll` method. Properties:
4845
*
4946
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
5047
*
@@ -59,22 +56,21 @@ function destroyAll(resourceName, params, options) {
5956
var DS = this;
6057
var deferred = DS.$q.defer();
6158
var promise = deferred.promise;
59+
var definition = DS.definitions[resourceName];
6260

6361
try {
6462
var IA = DS.errors.IA;
6563

6664
options = options || {};
6765

68-
if (!DS.definitions[resourceName]) {
66+
if (!definition) {
6967
throw new DS.errors.NER(errorPrefix(resourceName) + resourceName);
7068
} else if (!DS.utils.isObject(params)) {
7169
throw new IA(errorPrefix(resourceName) + 'params: Must be an object!');
7270
} else if (!DS.utils.isObject(options)) {
7371
throw new IA(errorPrefix(resourceName) + 'options: Must be an object!');
7472
}
7573

76-
var definition = DS.definitions[resourceName];
77-
7874
promise = promise
7975
.then(function () {
8076
return DS.adapters[options.adapter || definition.defaultAdapter].destroyAll(definition, params, options);

src/datastore/async_methods/find.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function errorPrefix(resourceName, id) {
77
* @id DS.async_methods:find
88
* @name find
99
* @description
10-
* Asynchronously return the resource with the given id from the server. The result will be added to the data
11-
* store when it returns from the server.
10+
* The "R" in "CRUD". Delegate to the `find` method of whichever adapter is being used (http by default) and inject the
11+
* resulting item into the data store.
1212
*
1313
* ## Signature:
1414
* ```js
@@ -18,28 +18,27 @@ function errorPrefix(resourceName, id) {
1818
* ## Example:
1919
*
2020
* ```js
21-
* DS.get('document', 5); // undefined
22-
* DS.find('document', 5).then(function (document) {
23-
* document; // { id: 5, author: 'John Anderson' }
21+
* DS.get('document', 5); // undefined
22+
* DS.find('document', 5).then(function (document) {
23+
* document; // { id: 5, author: 'John Anderson' }
2424
*
25-
* DS.get('document', 5); // { id: 5, author: 'John Anderson' }
26-
* }, function (err) {
27-
* // Handled errors
28-
* });
25+
* // the document is now in the data store
26+
* DS.get('document', 5); // { id: 5, author: 'John Anderson' }
27+
* });
2928
* ```
3029
*
3130
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
3231
* @param {string|number} id The primary key of the item to retrieve.
33-
* @param {object=} options Optional configuration. Properties:
32+
* @param {object=} options Optional configuration. Also passed along to the adapter's `find` method. Properties:
3433
*
3534
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
36-
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
35+
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the adapter into the data store. Default: `true`.
3736
*
3837
* @returns {Promise} Promise produced by the `$q` service.
3938
*
4039
* ## Resolves with:
4140
*
42-
* - `{object}` - `item` - The item with the primary key specified by `id`.
41+
* - `{object}` - `item` - The item returned by the adapter.
4342
*
4443
* ## Rejects with:
4544
*

src/datastore/async_methods/findAll.js

+21-23
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function _findAll(resourceName, params, options) {
8080
* @id DS.async_methods:findAll
8181
* @name findAll
8282
* @description
83-
* Asynchronously return the resource from the server filtered by the query. The results will be added to the data
84-
* store when it returns from the server.
83+
* The "R" in "CRUD". Delegate to the `findAll` method of whichever adapter is being used (http by default) and inject
84+
* the resulting collection into the data store.
8585
*
8686
* ## Signature:
8787
* ```js
@@ -91,46 +91,44 @@ function _findAll(resourceName, params, options) {
9191
* ## Example:
9292
*
9393
* ```js
94-
* var params = {
95-
* where: {
96-
* author: {
97-
* '==': 'John Anderson'
98-
* }
99-
* }
100-
* };
94+
* var params = {
95+
* where: {
96+
* author: {
97+
* '==': 'John Anderson'
98+
* }
99+
* }
100+
* };
101101
*
102-
* DS.findAll('document', params).then(function (documents) {
103-
* documents; // [{ id: '1', author: 'John Anderson', title: 'How to cook' },
104-
* // { id: '2', author: 'John Anderson', title: 'How NOT to cook' }]
102+
* DS.filter('document', params); // []
103+
* DS.findAll('document', params).then(function (documents) {
104+
* documents; // [{ id: '1', author: 'John Anderson', title: 'How to cook' },
105+
* // { id: '2', author: 'John Anderson', title: 'How NOT to cook' }]
105106
*
106-
* // The documents are now in the data store
107-
* DS.filter('document', params); // [{ id: '1', author: 'John Anderson', title: 'How to cook' },
108-
* // { id: '2', author: 'John Anderson', title: 'How NOT to cook' }]
109-
*
110-
* }, function (err) {
111-
* // handle error
112-
* });
107+
* // The documents are now in the data store
108+
* DS.filter('document', params); // [{ id: '1', author: 'John Anderson', title: 'How to cook' },
109+
* // { id: '2', author: 'John Anderson', title: 'How NOT to cook' }]
110+
* });
113111
* ```
114112
*
115113
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
116-
* @param {object=} params Parameter object that is serialized into the query string. Properties:
114+
* @param {object=} params Parameter object that is serialized into the query string. Default properties:
117115
*
118116
* - `{object=}` - `where` - Where clause.
119117
* - `{number=}` - `limit` - Limit clause.
120118
* - `{number=}` - `skip` - Skip clause.
121119
* - `{number=}` - `offset` - Same as skip.
122120
* - `{string|array=}` - `orderBy` - OrderBy clause.
123121
*
124-
* @param {object=} options Optional configuration. Properties:
122+
* @param {object=} options Optional configuration. Also passed along to the adapter's `findAll` method. Properties:
125123
*
126124
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
127-
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
125+
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the adapter into the data store. Default: `true`.
128126
*
129127
* @returns {Promise} Promise produced by the `$q` service.
130128
*
131129
* ## Resolves with:
132130
*
133-
* - `{array}` - `items` - The collection of items returned by the server.
131+
* - `{array}` - `items` - The collection of items returned by the adapter.
134132
*
135133
* ## Rejects with:
136134
*

src/datastore/async_methods/loadRelations.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function errorPrefix(resourceName) {
1111
*
1212
* ## Signature:
1313
* ```js
14-
* DS.loadRelations(resourceName, instance(Id), relations[, options])
14+
* DS.loadRelations(resourceName, instance|id, relations[, options])
1515
* ```
1616
*
1717
* ## Examples:
@@ -42,7 +42,7 @@ function errorPrefix(resourceName) {
4242
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
4343
* @param {string|number|object} instance The instance or the id of the instance for which relations are to be loaded.
4444
* @param {string|array=} relations The relation(s) to load.
45-
* @param {object=} options Optional configuration that is passed to the `find` and `findAll` methods that may be called.
45+
* @param {object=} options Optional configuration. Also passed along to the adapter's `find` or `findAll` methods.
4646
*
4747
* @returns {Promise} Promise produced by the `$q` service.
4848
*

src/datastore/async_methods/refresh.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@ function errorPrefix(resourceName, id) {
77
* @id DS.async_methods:refresh
88
* @name refresh
99
* @description
10-
* Like find(), except the resource is only refreshed from the server if it already exists in the data store.
10+
* Like `DS.find`, except the resource is only refreshed from the adapter if it already exists in the data store.
1111
*
1212
* ## Signature:
1313
* ```js
14-
* DS.refresh(resourceName, id)
14+
* DS.refresh(resourceName, id[, options])
1515
* ```
1616
* ## Example:
1717
*
1818
* ```js
19-
* // Exists in the data store, but we want a fresh copy
20-
* DS.get('document', 5);
19+
* // Exists in the data store, but we want a fresh copy
20+
* DS.get('document', 5);
2121
*
22-
* DS.refresh('document', 5)
23-
* .then(function (document) {
24-
* document; // The fresh copy
25-
* });
22+
* DS.refresh('document', 5).then(function (document) {
23+
* document; // The fresh copy
24+
* });
2625
*
27-
* // Does not exist in the data store
28-
* DS.get('document', 6); // undefined
26+
* // Does not exist in the data store
27+
* DS.get('document', 6); // undefined
2928
*
30-
* DS.refresh('document', 6).then(function (document) {
31-
* document; // undeinfed
32-
* }); // false
29+
* DS.refresh('document', 6).then(function (document) {
30+
* document; // undefined
31+
* });
3332
* ```
3433
*
3534
* ## Throws
@@ -38,13 +37,14 @@ function errorPrefix(resourceName, id) {
3837
* - `{NonexistentResourceError}`
3938
*
4039
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
41-
* @param {string|number} id The primary key of the item to refresh from the server.
42-
* @param {object=} options Optional configuration passed through to `DS.find` if it is called.
43-
* @returns {Promise} A Promise created by the $q server.
40+
* @param {string|number} id The primary key of the item to refresh from the adapter.
41+
* @param {object=} options Optional configuration. Also passed along to the adapter's `find` method.
42+
* @returns {Promise} A Promise created by the $q service.
4443
*
4544
* ## Resolves with:
4645
*
47-
* - `{object}` - `item` - A reference to the refreshed item.
46+
* - `{object|undefined}` - `item` - The item returned by the adapter or `undefined` if the item wasn't already in the
47+
* data store.
4848
*
4949
* ## Rejects with:
5050
*

src/datastore/async_methods/save.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ function errorPrefix(resourceName, id) {
77
* @id DS.async_methods:save
88
* @name save
99
* @description
10-
* Save the item of the type specified by `resourceName` that has the primary key specified by `id`.
10+
* The "U" in "CRUD". Persist a single item already in the store and in it's current form to whichever adapter is being
11+
* used (http by default) and inject the resulting item into the data store.
1112
*
1213
* ## Signature:
1314
* ```js
@@ -17,28 +18,27 @@ function errorPrefix(resourceName, id) {
1718
* ## Example:
1819
*
1920
* ```js
20-
* var document = DS.get('document', 'ee7f3f4d-98d5-4934-9e5a-6a559b08479f');
21+
* var document = DS.get('document', 5);
2122
*
22-
* document.title = 'How to cook in style';
23+
* document.title = 'How to cook in style';
2324
*
24-
* DS.save('document', 'ee7f3f4d-98d5-4934-9e5a-6a559b08479f')
25-
* .then(function (document) {
26-
* document; // A reference to the document that's been saved to the server
27-
* });
25+
* DS.save('document', 5).then(function (document) {
26+
* document; // A reference to the document that's been persisted via an adapter
27+
* });
2828
* ```
2929
*
3030
* @param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
3131
* @param {string|number} id The primary key of the item to save.
32-
* @param {object=} options Optional configuration. Properties::
32+
* @param {object=} options Optional configuration. Also passed along to the adapter's `update` method. Properties:
3333
*
34-
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
35-
* - `{boolean=}` - `changesOnly` - Only send changed and added values back to the server.
34+
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the adapter into the data store. Default: `true`.
35+
* - `{boolean=}` - `changesOnly` - Only send changed and added values to the adapter. Default: `false`.
3636
*
3737
* @returns {Promise} Promise produced by the `$q` service.
3838
*
3939
* ## Resolves with:
4040
*
41-
* - `{object}` - `item` - A reference to the newly saved item.
41+
* - `{object}` - `item` - The item returned by the adapter.
4242
*
4343
* ## Rejects with:
4444
*
@@ -50,13 +50,14 @@ function save(resourceName, id, options) {
5050
var DS = this;
5151
var deferred = DS.$q.defer();
5252
var promise = deferred.promise;
53+
var definition = DS.definitions[resourceName];
5354

5455
try {
5556
var IA = DS.errors.IA;
5657

5758
options = options || {};
5859

59-
if (!DS.definitions[resourceName]) {
60+
if (!definition) {
6061
throw new DS.errors.NER(errorPrefix(resourceName, id) + resourceName);
6162
} else if (!DS.utils.isString(id) && !DS.utils.isNumber(id)) {
6263
throw new IA(errorPrefix(resourceName, id) + 'id: Must be a string or a number!');
@@ -69,7 +70,6 @@ function save(resourceName, id, options) {
6970
throw new DS.errors.R(errorPrefix(resourceName, id) + 'id: "' + id + '" not found!');
7071
}
7172

72-
var definition = DS.definitions[resourceName];
7373
var resource = DS.store[resourceName];
7474

7575
if (!('cacheResponse' in options)) {

0 commit comments

Comments
 (0)