- Notifications
You must be signed in to change notification settings - Fork77
adds DS.getAll#232
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
adds DS.getAll#232
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
97 changes: 83 additions & 14 deletionsdist/angular-data.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionsdist/angular-data.min.js
Large diffs are not rendered by default.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
58 changes: 58 additions & 0 deletionssrc/datastore/sync_methods/getAll.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| function errorPrefix(resourceName) { | ||
| return 'DS.getAll(' + resourceName + '[, ids]): '; | ||
| } | ||
| /** | ||
| * @doc method | ||
| * @id DS.sync methods:getAll | ||
| * @name getAll | ||
| * @description | ||
| * Synchronously return all of the resource. | ||
| * | ||
| * ## Signature: | ||
| * ```js | ||
| * DS.getAll(resourceName[, ids]) | ||
| * ``` | ||
| * | ||
| * ## Example: | ||
| * | ||
| * ```js | ||
| * DS.getAll('document'); // [{ author: 'John Anderson', id: 5 }] | ||
| * ``` | ||
| * | ||
| * ## Throws | ||
| * | ||
| * - `{IllegalArgumentError}` | ||
| * - `{NonexistentResourceError}` | ||
| * | ||
| * @param {string} resourceName The resource type, e.g. 'user', 'comment', etc. | ||
| * @param {array} ids Optional list of primary keys to filter the array of results by. | ||
| * | ||
| * @returns {array} The items of the type specified by `resourceName`. | ||
| */ | ||
| function getAll(resourceName, ids) { | ||
| var DS = this; | ||
| var IA = DS.errors.IA; | ||
| var resource; | ||
| var collection = []; | ||
| if (!DS.definitions[resourceName]) { | ||
| throw new DS.errors.NER(errorPrefix(resourceName) + resourceName); | ||
| } else if (arguments.length === 2 && !DS.utils.isArray(ids)) { | ||
| throw new IA(errorPrefix(resourceName, ids) + 'ids: Must be an array!'); | ||
| } | ||
| resource = DS.store[resourceName]; | ||
| if (DS.utils.isArray(ids)) { | ||
| for (var i = 0; i < ids.length; i++) { | ||
| collection.push(resource.index.get(ids[i])); | ||
| } | ||
| } else { | ||
| collection = resource.collection.slice(); | ||
| } | ||
| return collection; | ||
| } | ||
| module.exports = getAll; |
10 changes: 10 additions & 0 deletionssrc/datastore/sync_methods/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletionstest/integration/datastore/sync_methods/getAll.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| describe('DS.getAll(resourceName)', function () { | ||
| function errorPrefix(resourceName) { | ||
| return 'DS.getAll(' + resourceName + '[, ids]): '; | ||
| } | ||
| beforeEach(startInjector); | ||
| it('should throw an error when method pre-conditions are not met', function () { | ||
| assert.throws(function () { | ||
| DS.getAll('does not exist'); | ||
| }, DS.errors.NonexistentResourceError, errorPrefix('does not exist', {}) + 'does not exist is not a registered resource!'); | ||
| angular.forEach(TYPES_EXCEPT_ARRAY, function (key) { | ||
| assert.throws(function () { | ||
| DS.getAll('post', key); | ||
| }, DS.errors.IllegalArgumentError, errorPrefix('post', key) + 'ids: Must be an array!'); | ||
| }); | ||
| }); | ||
| it('should return an array of all items in the store', function() { | ||
| assert.isArray(DS.getAll('post'), 'should be an empty array'); | ||
| }); | ||
| it('should return results that match a set of ids', function() { | ||
| DS.inject('post', [ p1, p2, p3 ]); | ||
| var posts = DS.getAll('post', [ 5, 7 ]); | ||
| assert.deepEqual(angular.toJson(posts), angular.toJson([ p1, p3 ])); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.