1
1
/**
2
2
* @author Jason Dobry <[email protected] >
3
3
* @file angular-data.js
4
- * @version 0.9.0 - Homepage <http://angular-data.codetrain.io/>
4
+ * @version 0.9.1 - Homepage <http://angular-data.codetrain.io/>
5
5
* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
6
6
* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
7
7
*
@@ -1570,7 +1570,9 @@ function DSHttpAdapterProvider() {
1570
1570
options = options || { } ;
1571
1571
options . params = options . params || { } ;
1572
1572
if ( params ) {
1573
- params . query = params . query ? defaults . queryTransform ( resourceConfig . name , params . query ) : params . query ;
1573
+ if ( params . query ) {
1574
+ params . query = defaults . queryTransform ( resourceConfig . name , params . query ) ;
1575
+ }
1574
1576
DSUtils . deepMixIn ( options . params , params ) ;
1575
1577
}
1576
1578
return this . DEL (
@@ -1591,7 +1593,9 @@ function DSHttpAdapterProvider() {
1591
1593
options = options || { } ;
1592
1594
options . params = options . params || { } ;
1593
1595
if ( params ) {
1594
- params . query = params . query ? defaults . queryTransform ( resourceConfig . name , params . query ) : params . query ;
1596
+ if ( params . query ) {
1597
+ params . query = defaults . queryTransform ( resourceConfig . name , params . query ) ;
1598
+ }
1595
1599
DSUtils . deepMixIn ( options . params , params ) ;
1596
1600
}
1597
1601
return this . GET (
@@ -1613,7 +1617,9 @@ function DSHttpAdapterProvider() {
1613
1617
options = options || { } ;
1614
1618
options . params = options . params || { } ;
1615
1619
if ( params ) {
1616
- params . query = params . query ? defaults . queryTransform ( resourceConfig . name , params . query ) : params . query ;
1620
+ if ( params . query ) {
1621
+ params . query = defaults . queryTransform ( resourceConfig . name , params . query ) ;
1622
+ }
1617
1623
DSUtils . deepMixIn ( options . params , params ) ;
1618
1624
}
1619
1625
return this . PUT (
@@ -2182,7 +2188,7 @@ function find(resourceName, id, options) {
2182
2188
}
2183
2189
} , function ( err ) {
2184
2190
delete resource . pendingQueries [ id ] ;
2185
- return err ;
2191
+ return _this . $q . reject ( err ) ;
2186
2192
} ) ;
2187
2193
}
2188
2194
@@ -2212,12 +2218,11 @@ function processResults(utils, data, resourceName, queryHash) {
2212
2218
delete resource . pendingQueries [ queryHash ] ;
2213
2219
resource . completedQueries [ queryHash ] = new Date ( ) . getTime ( ) ;
2214
2220
2215
- // Merge the new values into the cache
2216
- this . inject ( resourceName , data ) ;
2217
-
2218
2221
// Update modified timestamp of collection
2219
2222
resource . collectionModified = utils . updateTimestamp ( resource . collectionModified ) ;
2220
- return data ;
2223
+
2224
+ // Merge the new values into the cache
2225
+ return this . inject ( resourceName , data ) ;
2221
2226
}
2222
2227
2223
2228
function _findAll ( utils , resourceName , params , options ) {
@@ -2243,14 +2248,14 @@ function _findAll(utils, resourceName, params, options) {
2243
2248
try {
2244
2249
return processResults . apply ( _this , [ utils , data , resourceName , queryHash ] ) ;
2245
2250
} catch ( err ) {
2246
- throw new _this . errors . UnhandledError ( err ) ;
2251
+ return _this . $q . reject ( _this . errors . UnhandledError ( err ) ) ;
2247
2252
}
2248
2253
} else {
2249
2254
return data ;
2250
2255
}
2251
2256
} , function ( err ) {
2252
2257
delete resource . pendingQueries [ queryHash ] ;
2253
- return err ;
2258
+ return _this . $q . reject ( err ) ;
2254
2259
} ) ;
2255
2260
}
2256
2261
@@ -2302,7 +2307,7 @@ function _findAll(utils, resourceName, params, options) {
2302
2307
* ```
2303
2308
*
2304
2309
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
2305
- * @param {object } params Parameter object that is serialized into the query string. Properties:
2310
+ * @param {object= } params Parameter object that is serialized into the query string. Properties:
2306
2311
*
2307
2312
* - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
2308
2313
* - `{object=}` - `where` - Where clause.
@@ -2332,6 +2337,7 @@ function findAll(resourceName, params, options) {
2332
2337
_this = this ;
2333
2338
2334
2339
options = options || { } ;
2340
+ params = params || { } ;
2335
2341
2336
2342
if ( ! this . definitions [ resourceName ] ) {
2337
2343
deferred . reject ( new this . errors . RuntimeError ( errorPrefix + resourceName + ' is not a registered resource!' ) ) ;
@@ -4048,7 +4054,7 @@ var errorPrefix = 'DS.filter(resourceName, params[, options]): ';
4048
4054
* - `{UnhandledError}`
4049
4055
*
4050
4056
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
4051
- * @param {object } params Parameter object that is serialized into the query string. Properties:
4057
+ * @param {object= } params Parameter object that is serialized into the query string. Properties:
4052
4058
*
4053
4059
* - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
4054
4060
* - `{object=}` - `where` - Where clause.
@@ -4065,7 +4071,7 @@ function filter(resourceName, params, options) {
4065
4071
4066
4072
if ( ! this . definitions [ resourceName ] ) {
4067
4073
throw new this . errors . RuntimeError ( errorPrefix + resourceName + ' is not a registered resource!' ) ;
4068
- } else if ( ! this . utils . isObject ( params ) ) {
4074
+ } else if ( params && ! this . utils . isObject ( params ) ) {
4069
4075
throw new this . errors . IllegalArgumentError ( errorPrefix + 'params: Must be an object!' , { params : { actual : typeof params , expected : 'object' } } ) ;
4070
4076
} else if ( ! this . utils . isObject ( options ) ) {
4071
4077
throw new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ;
@@ -4077,7 +4083,7 @@ function filter(resourceName, params, options) {
4077
4083
_this = this ;
4078
4084
4079
4085
// Protect against null
4080
- params . query = params . query || { } ;
4086
+ params = params || { } ;
4081
4087
4082
4088
var queryHash = this . utils . toJson ( params ) ;
4083
4089
@@ -4090,6 +4096,7 @@ function filter(resourceName, params, options) {
4090
4096
}
4091
4097
}
4092
4098
4099
+ params . query = params . query || { } ;
4093
4100
// The query has been completed, so hit the cache with the query
4094
4101
var filtered = this . utils . filter ( resource . collection , function ( attrs ) {
4095
4102
var keep = true ,
@@ -4220,13 +4227,14 @@ function get(resourceName, id, options) {
4220
4227
} else if ( ! this . utils . isObject ( options ) ) {
4221
4228
throw new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ;
4222
4229
}
4230
+ var _this = this ;
4223
4231
4224
4232
try {
4225
4233
// cache miss, request resource from server
4226
4234
var item = this . store [ resourceName ] . index . get ( id ) ;
4227
4235
if ( ! item && options . loadFromServer ) {
4228
4236
this . find ( resourceName , id ) . then ( null , function ( err ) {
4229
- throw err ;
4237
+ return _this . $q . reject ( err ) ;
4230
4238
} ) ;
4231
4239
}
4232
4240
@@ -4470,9 +4478,11 @@ function _inject(definition, resource, attrs) {
4470
4478
}
4471
4479
}
4472
4480
4481
+ var injected ;
4473
4482
if ( _this . utils . isArray ( attrs ) ) {
4483
+ injected = [ ] ;
4474
4484
for ( var i = 0 ; i < attrs . length ; i ++ ) {
4475
- _inject . call ( _this , definition , resource , attrs [ i ] ) ;
4485
+ injected . push ( _inject . call ( _this , definition , resource , attrs [ i ] ) ) ;
4476
4486
}
4477
4487
} else {
4478
4488
if ( ! ( definition . idAttribute in attrs ) ) {
@@ -4517,12 +4527,14 @@ function _inject(definition, resource, attrs) {
4517
4527
}
4518
4528
resource . saved [ id ] = _this . utils . updateTimestamp ( resource . saved [ id ] ) ;
4519
4529
definition . afterInject ( definition . name , item ) ;
4530
+ injected = item ;
4520
4531
} catch ( err ) {
4521
4532
$log . error ( err ) ;
4522
4533
$log . error ( 'inject failed!' , definition . name , attrs ) ;
4523
4534
}
4524
4535
}
4525
4536
}
4537
+ return injected ;
4526
4538
}
4527
4539
4528
4540
/**
@@ -4586,18 +4598,15 @@ function inject(resourceName, attrs, options) {
4586
4598
_this = this ;
4587
4599
4588
4600
try {
4601
+ var injected ;
4589
4602
if ( ! this . $rootScope . $$phase ) {
4590
4603
this . $rootScope . $apply ( function ( ) {
4591
- _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4604
+ injected = _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4592
4605
} ) ;
4593
4606
} else {
4594
- _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4595
- }
4596
- if ( _this . utils . isArray ( attrs ) ) {
4597
- return attrs ;
4598
- } else {
4599
- return this . get ( resourceName , attrs [ definition . idAttribute ] ) ;
4607
+ injected = _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4600
4608
}
4609
+ return injected ;
4601
4610
} catch ( err ) {
4602
4611
if ( ! ( err instanceof this . errors . RuntimeError ) ) {
4603
4612
throw new this . errors . UnhandledError ( err ) ;
@@ -4963,7 +4972,7 @@ module.exports = [function () {
4963
4972
* @id angular-data
4964
4973
* @name angular-data
4965
4974
* @description
4966
- * __Version:__ 0.9.0
4975
+ * __Version:__ 0.9.1
4967
4976
*
4968
4977
* ## Install
4969
4978
*
0 commit comments