Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
jmdobry merged 1 commit intojs-data:v1fromiamdtang:v1
Nov 7, 2014
Merged
Show file tree
Hide file tree
Changes fromall 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
97 changes: 83 additions & 14 deletionsdist/angular-data.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4860,7 +4860,7 @@ function DSProvider() {

module.exports = DSProvider;

},{"./async_methods":61,"./sync_methods":81}],68:[function(require,module,exports){
},{"./async_methods":61,"./sync_methods":82}],68:[function(require,module,exports){
function errorPrefix(resourceName) {
return 'DS.bindAll(scope, expr, ' + resourceName + ', params[, cb]): ';
}
Expand DownExpand Up@@ -6127,6 +6127,65 @@ function get(resourceName, id, options) {
module.exports = get;

},{}],80:[function(require,module,exports){
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;
},{}],81:[function(require,module,exports){
function errorPrefix(resourceName, id) {
return 'DS.hasChanges(' + resourceName + ', ' + id + '): ';
}
Expand DownExpand Up@@ -6191,7 +6250,7 @@ function hasChanges(resourceName, id) {

module.exports = hasChanges;

},{}],81:[function(require,module,exports){
},{}],82:[function(require,module,exports){
module.exports = {

/**
Expand DownExpand Up@@ -6314,6 +6373,16 @@ module.exports = {
*/
get: require('./get'),

/**
* @doc method
* @id DS.sync methods:getAll
* @name getAll
* @methodOf DS
* @description
* See [DS.getAll](/documentation/api/api/DS.sync methods:getAll).
*/
getAll: require('./getAll'),

/**
* @doc method
* @id DS.sync methods:hasChanges
Expand DownExpand Up@@ -6405,7 +6474,7 @@ module.exports = {
unlinkInverse: require('./unlinkInverse')
};

},{"./bindAll":68,"./bindOne":69,"./changeHistory":70,"./changes":71,"./compute":72,"./createInstance":73,"./defineResource":74,"./digest":75,"./eject":76,"./ejectAll":77,"./filter":78,"./get":79,"./hasChanges":80,"./inject":82,"./lastModified":83,"./lastSaved":84,"./link":85,"./linkAll":86,"./linkInverse":87,"./previous":88,"./unlinkInverse":89}],82:[function(require,module,exports){
},{"./bindAll":68,"./bindOne":69,"./changeHistory":70,"./changes":71,"./compute":72,"./createInstance":73,"./defineResource":74,"./digest":75,"./eject":76,"./ejectAll":77,"./filter":78,"./get":79,"./getAll":80,"./hasChanges":81,"./inject":83,"./lastModified":84,"./lastSaved":85,"./link":86,"./linkAll":87,"./linkInverse":88,"./previous":89,"./unlinkInverse":90}],83:[function(require,module,exports){
var observe = require('../../../lib/observe-js/observe-js');
var _compute = require('./compute')._compute;

Expand DownExpand Up@@ -6714,7 +6783,7 @@ function inject(resourceName, attrs, options) {

module.exports = inject;

},{"../../../lib/observe-js/observe-js":1,"./compute":72}],83:[function(require,module,exports){
},{"../../../lib/observe-js/observe-js":1,"./compute":72}],84:[function(require,module,exports){
function errorPrefix(resourceName, id) {
return 'DS.lastModified(' + resourceName + '[, ' + id + ']): ';
}
Expand DownExpand Up@@ -6773,7 +6842,7 @@ function lastModified(resourceName, id) {

module.exports = lastModified;

},{}],84:[function(require,module,exports){
},{}],85:[function(require,module,exports){
function errorPrefix(resourceName, id) {
return 'DS.lastSaved(' + resourceName + '[, ' + id + ']): ';
}
Expand DownExpand Up@@ -6837,7 +6906,7 @@ function lastSaved(resourceName, id) {

module.exports = lastSaved;

},{}],85:[function(require,module,exports){
},{}],86:[function(require,module,exports){
function errorPrefix(resourceName) {
return 'DS.link(' + resourceName + ', id[, relations]): ';
}
Expand DownExpand Up@@ -6939,7 +7008,7 @@ function link(resourceName, id, relations) {

module.exports = link;

},{}],86:[function(require,module,exports){
},{}],87:[function(require,module,exports){
function errorPrefix(resourceName) {
return 'DS.linkAll(' + resourceName + '[, params][, relations]): ';
}
Expand DownExpand Up@@ -7056,7 +7125,7 @@ function linkAll(resourceName, params, relations) {

module.exports = linkAll;

},{}],87:[function(require,module,exports){
},{}],88:[function(require,module,exports){
function errorPrefix(resourceName) {
return 'DS.linkInverse(' + resourceName + ', id[, relations]): ';
}
Expand DownExpand Up@@ -7154,7 +7223,7 @@ function linkInverse(resourceName, id, relations) {

module.exports = linkInverse;

},{}],88:[function(require,module,exports){
},{}],89:[function(require,module,exports){
function errorPrefix(resourceName, id) {
return 'DS.previous(' + resourceName + '[, ' + id + ']): ';
}
Expand DownExpand Up@@ -7211,7 +7280,7 @@ function previous(resourceName, id) {

module.exports = previous;

},{}],89:[function(require,module,exports){
},{}],90:[function(require,module,exports){
function errorPrefix(resourceName) {
return 'DS.unlinkInverse(' + resourceName + ', id[, relations]): ';
}
Expand DownExpand Up@@ -7312,7 +7381,7 @@ function unlinkInverse(resourceName, id, relations) {

module.exports = unlinkInverse;

},{}],90:[function(require,module,exports){
},{}],91:[function(require,module,exports){
/**
* @doc function
* @id errors.types:IllegalArgumentError
Expand DownExpand Up@@ -7445,7 +7514,7 @@ module.exports = [function () {
};
}];

},{}],91:[function(require,module,exports){
},{}],92:[function(require,module,exports){
(function (window, angular, undefined) {
'use strict';

Expand DownExpand Up@@ -7534,7 +7603,7 @@ module.exports = [function () {

})(window, window.angular);

},{"./adapters/http":54,"./adapters/localStorage":55,"./datastore":67,"./errors":90,"./utils":92}],92:[function(require,module,exports){
},{"./adapters/http":54,"./adapters/localStorage":55,"./datastore":67,"./errors":91,"./utils":93}],93:[function(require,module,exports){
var DSErrors = require('./errors');

function Events(target) {
Expand DownExpand Up@@ -7747,4 +7816,4 @@ module.exports = ['$q', function ($q) {
};
}];

},{"./errors":90,"mout/array/contains":2,"mout/array/filter":3,"mout/array/find":4,"mout/array/remove":9,"mout/array/slice":10,"mout/array/sort":11,"mout/array/toLookup":12,"mout/lang/isBoolean":19,"mout/lang/isEmpty":20,"mout/lang/isRegExp":25,"mout/object/deepMixIn":31,"mout/object/keys":35,"mout/object/merge":36,"mout/object/mixIn":37,"mout/object/pick":39,"mout/object/set":40,"mout/random/guid":42,"mout/string/makePath":49,"mout/string/pascalCase":50,"mout/string/upperCase":53}]},{},[91]);
},{"./errors":91,"mout/array/contains":2,"mout/array/filter":3,"mout/array/find":4,"mout/array/remove":9,"mout/array/slice":10,"mout/array/sort":11,"mout/array/toLookup":12,"mout/lang/isBoolean":19,"mout/lang/isEmpty":20,"mout/lang/isRegExp":25,"mout/object/deepMixIn":31,"mout/object/keys":35,"mout/object/merge":36,"mout/object/mixIn":37,"mout/object/pick":39,"mout/object/set":40,"mout/random/guid":42,"mout/string/makePath":49,"mout/string/pascalCase":50,"mout/string/upperCase":53}]},{},[92]);
4 changes: 2 additions & 2 deletionsdist/angular-data.min.js
View file
Open in desktop

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletionssrc/datastore/sync_methods/getAll.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -120,6 +120,16 @@ module.exports = {
*/
get:require('./get'),

/**
*@doc method
*@id DS.sync methods:getAll
*@name getAll
*@methodOf DS
*@description
* See [DS.getAll](/documentation/api/api/DS.sync methods:getAll).
*/
getAll:require('./getAll'),

/**
*@doc method
*@id DS.sync methods:hasChanges
Expand Down
27 changes: 27 additions & 0 deletionstest/integration/datastore/sync_methods/getAll.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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 ]));
});
});

[8]ページ先頭

©2009-2025 Movatter.jp