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

Commit3e11ffa

Browse files
committed
Merge pull request#232 from skaterdav85/v1
adds DS.getAll
2 parentsa2a9e1a +66b99f5 commit3e11ffa

File tree

5 files changed

+180
-16
lines changed

5 files changed

+180
-16
lines changed

‎dist/angular-data.js‎

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4860,7 +4860,7 @@ function DSProvider() {
48604860

48614861
module.exports=DSProvider;
48624862

4863-
},{"./async_methods":61,"./sync_methods":81}],68:[function(require,module,exports){
4863+
},{"./async_methods":61,"./sync_methods":82}],68:[function(require,module,exports){
48644864
functionerrorPrefix(resourceName){
48654865
return'DS.bindAll(scope, expr, '+resourceName+', params[, cb]): ';
48664866
}
@@ -6127,6 +6127,65 @@ function get(resourceName, id, options) {
61276127
module.exports=get;
61286128

61296129
},{}],80:[function(require,module,exports){
6130+
functionerrorPrefix(resourceName){
6131+
return'DS.getAll('+resourceName+'[, ids]): ';
6132+
}
6133+
6134+
/**
6135+
*@doc method
6136+
*@id DS.sync methods:getAll
6137+
*@name getAll
6138+
*@description
6139+
* Synchronously return all of the resource.
6140+
*
6141+
* ## Signature:
6142+
* ```js
6143+
* DS.getAll(resourceName[, ids])
6144+
* ```
6145+
*
6146+
* ## Example:
6147+
*
6148+
* ```js
6149+
* DS.getAll('document'); // [{ author: 'John Anderson', id: 5 }]
6150+
* ```
6151+
*
6152+
* ## Throws
6153+
*
6154+
* - `{IllegalArgumentError}`
6155+
* - `{NonexistentResourceError}`
6156+
*
6157+
*@param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
6158+
*@param {array} ids Optional list of primary keys to filter the array of results by.
6159+
*
6160+
*@returns {array} The items of the type specified by `resourceName`.
6161+
*/
6162+
functiongetAll(resourceName,ids){
6163+
varDS=this;
6164+
varIA=DS.errors.IA;
6165+
varresource;
6166+
varcollection=[];
6167+
6168+
if(!DS.definitions[resourceName]){
6169+
thrownewDS.errors.NER(errorPrefix(resourceName)+resourceName);
6170+
}elseif(arguments.length===2&&!DS.utils.isArray(ids)){
6171+
thrownewIA(errorPrefix(resourceName,ids)+'ids: Must be an array!');
6172+
}
6173+
6174+
resource=DS.store[resourceName];
6175+
6176+
if(DS.utils.isArray(ids)){
6177+
for(vari=0;i<ids.length;i++){
6178+
collection.push(resource.index.get(ids[i]));
6179+
}
6180+
}else{
6181+
collection=resource.collection.slice();
6182+
}
6183+
6184+
returncollection;
6185+
}
6186+
6187+
module.exports=getAll;
6188+
},{}],81:[function(require,module,exports){
61306189
functionerrorPrefix(resourceName,id){
61316190
return'DS.hasChanges('+resourceName+', '+id+'): ';
61326191
}
@@ -6191,7 +6250,7 @@ function hasChanges(resourceName, id) {
61916250

61926251
module.exports=hasChanges;
61936252

6194-
},{}],81:[function(require,module,exports){
6253+
},{}],82:[function(require,module,exports){
61956254
module.exports={
61966255

61976256
/**
@@ -6314,6 +6373,16 @@ module.exports = {
63146373
*/
63156374
get:require('./get'),
63166375

6376+
/**
6377+
*@doc method
6378+
*@id DS.sync methods:getAll
6379+
*@name getAll
6380+
*@methodOf DS
6381+
*@description
6382+
* See [DS.getAll](/documentation/api/api/DS.sync methods:getAll).
6383+
*/
6384+
getAll:require('./getAll'),
6385+
63176386
/**
63186387
*@doc method
63196388
*@id DS.sync methods:hasChanges
@@ -6405,7 +6474,7 @@ module.exports = {
64056474
unlinkInverse:require('./unlinkInverse')
64066475
};
64076476

6408-
},{"./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){
6477+
},{"./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){
64096478
varobserve=require('../../../lib/observe-js/observe-js');
64106479
var_compute=require('./compute')._compute;
64116480

@@ -6714,7 +6783,7 @@ function inject(resourceName, attrs, options) {
67146783

67156784
module.exports=inject;
67166785

6717-
},{"../../../lib/observe-js/observe-js":1,"./compute":72}],83:[function(require,module,exports){
6786+
},{"../../../lib/observe-js/observe-js":1,"./compute":72}],84:[function(require,module,exports){
67186787
functionerrorPrefix(resourceName,id){
67196788
return'DS.lastModified('+resourceName+'[, '+id+']): ';
67206789
}
@@ -6773,7 +6842,7 @@ function lastModified(resourceName, id) {
67736842

67746843
module.exports=lastModified;
67756844

6776-
},{}],84:[function(require,module,exports){
6845+
},{}],85:[function(require,module,exports){
67776846
functionerrorPrefix(resourceName,id){
67786847
return'DS.lastSaved('+resourceName+'[, '+id+']): ';
67796848
}
@@ -6837,7 +6906,7 @@ function lastSaved(resourceName, id) {
68376906

68386907
module.exports=lastSaved;
68396908

6840-
},{}],85:[function(require,module,exports){
6909+
},{}],86:[function(require,module,exports){
68416910
functionerrorPrefix(resourceName){
68426911
return'DS.link('+resourceName+', id[, relations]): ';
68436912
}
@@ -6939,7 +7008,7 @@ function link(resourceName, id, relations) {
69397008

69407009
module.exports=link;
69417010

6942-
},{}],86:[function(require,module,exports){
7011+
},{}],87:[function(require,module,exports){
69437012
functionerrorPrefix(resourceName){
69447013
return'DS.linkAll('+resourceName+'[, params][, relations]): ';
69457014
}
@@ -7056,7 +7125,7 @@ function linkAll(resourceName, params, relations) {
70567125

70577126
module.exports=linkAll;
70587127

7059-
},{}],87:[function(require,module,exports){
7128+
},{}],88:[function(require,module,exports){
70607129
functionerrorPrefix(resourceName){
70617130
return'DS.linkInverse('+resourceName+', id[, relations]): ';
70627131
}
@@ -7154,7 +7223,7 @@ function linkInverse(resourceName, id, relations) {
71547223

71557224
module.exports=linkInverse;
71567225

7157-
},{}],88:[function(require,module,exports){
7226+
},{}],89:[function(require,module,exports){
71587227
functionerrorPrefix(resourceName,id){
71597228
return'DS.previous('+resourceName+'[, '+id+']): ';
71607229
}
@@ -7211,7 +7280,7 @@ function previous(resourceName, id) {
72117280

72127281
module.exports=previous;
72137282

7214-
},{}],89:[function(require,module,exports){
7283+
},{}],90:[function(require,module,exports){
72157284
functionerrorPrefix(resourceName){
72167285
return'DS.unlinkInverse('+resourceName+', id[, relations]): ';
72177286
}
@@ -7312,7 +7381,7 @@ function unlinkInverse(resourceName, id, relations) {
73127381

73137382
module.exports=unlinkInverse;
73147383

7315-
},{}],90:[function(require,module,exports){
7384+
},{}],91:[function(require,module,exports){
73167385
/**
73177386
*@doc function
73187387
*@id errors.types:IllegalArgumentError
@@ -7445,7 +7514,7 @@ module.exports = [function () {
74457514
};
74467515
}];
74477516

7448-
},{}],91:[function(require,module,exports){
7517+
},{}],92:[function(require,module,exports){
74497518
(function(window,angular,undefined){
74507519
'use strict';
74517520

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

75357604
})(window,window.angular);
75367605

7537-
},{"./adapters/http":54,"./adapters/localStorage":55,"./datastore":67,"./errors":90,"./utils":92}],92:[function(require,module,exports){
7606+
},{"./adapters/http":54,"./adapters/localStorage":55,"./datastore":67,"./errors":91,"./utils":93}],93:[function(require,module,exports){
75387607
varDSErrors=require('./errors');
75397608

75407609
functionEvents(target){
@@ -7747,4 +7816,4 @@ module.exports = ['$q', function ($q) {
77477816
};
77487817
}];
77497818

7750-
},{"./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]);
7819+
},{"./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]);

‎dist/angular-data.min.js‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
functionerrorPrefix(resourceName){
2+
return'DS.getAll('+resourceName+'[, ids]): ';
3+
}
4+
5+
/**
6+
*@doc method
7+
*@id DS.sync methods:getAll
8+
*@name getAll
9+
*@description
10+
* Synchronously return all of the resource.
11+
*
12+
* ## Signature:
13+
* ```js
14+
* DS.getAll(resourceName[, ids])
15+
* ```
16+
*
17+
* ## Example:
18+
*
19+
* ```js
20+
* DS.getAll('document'); // [{ author: 'John Anderson', id: 5 }]
21+
* ```
22+
*
23+
* ## Throws
24+
*
25+
* - `{IllegalArgumentError}`
26+
* - `{NonexistentResourceError}`
27+
*
28+
*@param {string} resourceName The resource type, e.g. 'user', 'comment', etc.
29+
*@param {array} ids Optional list of primary keys to filter the array of results by.
30+
*
31+
*@returns {array} The items of the type specified by `resourceName`.
32+
*/
33+
functiongetAll(resourceName,ids){
34+
varDS=this;
35+
varIA=DS.errors.IA;
36+
varresource;
37+
varcollection=[];
38+
39+
if(!DS.definitions[resourceName]){
40+
thrownewDS.errors.NER(errorPrefix(resourceName)+resourceName);
41+
}elseif(arguments.length===2&&!DS.utils.isArray(ids)){
42+
thrownewIA(errorPrefix(resourceName,ids)+'ids: Must be an array!');
43+
}
44+
45+
resource=DS.store[resourceName];
46+
47+
if(DS.utils.isArray(ids)){
48+
for(vari=0;i<ids.length;i++){
49+
collection.push(resource.index.get(ids[i]));
50+
}
51+
}else{
52+
collection=resource.collection.slice();
53+
}
54+
55+
returncollection;
56+
}
57+
58+
module.exports=getAll;

‎src/datastore/sync_methods/index.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ module.exports = {
120120
*/
121121
get:require('./get'),
122122

123+
/**
124+
*@doc method
125+
*@id DS.sync methods:getAll
126+
*@name getAll
127+
*@methodOf DS
128+
*@description
129+
* See [DS.getAll](/documentation/api/api/DS.sync methods:getAll).
130+
*/
131+
getAll:require('./getAll'),
132+
123133
/**
124134
*@doc method
125135
*@id DS.sync methods:hasChanges
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
describe('DS.getAll(resourceName)',function(){
2+
functionerrorPrefix(resourceName){
3+
return'DS.getAll('+resourceName+'[, ids]): ';
4+
}
5+
6+
beforeEach(startInjector);
7+
8+
it('should throw an error when method pre-conditions are not met',function(){
9+
assert.throws(function(){
10+
DS.getAll('does not exist');
11+
},DS.errors.NonexistentResourceError,errorPrefix('does not exist',{})+'does not exist is not a registered resource!');
12+
13+
angular.forEach(TYPES_EXCEPT_ARRAY,function(key){
14+
assert.throws(function(){
15+
DS.getAll('post',key);
16+
},DS.errors.IllegalArgumentError,errorPrefix('post',key)+'ids: Must be an array!');
17+
});
18+
});
19+
it('should return an array of all items in the store',function(){
20+
assert.isArray(DS.getAll('post'),'should be an empty array');
21+
});
22+
it('should return results that match a set of ids',function(){
23+
DS.inject('post',[p1,p2,p3]);
24+
varposts=DS.getAll('post',[5,7]);
25+
assert.deepEqual(angular.toJson(posts),angular.toJson([p1,p3]));
26+
});
27+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp