11/**
22* @author Jason Dobry <jason.dobry@gmail.com>
33* @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/>
55* @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/>
66* @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77*
@@ -1570,7 +1570,9 @@ function DSHttpAdapterProvider() {
15701570 options = options || { } ;
15711571 options . params = options . params || { } ;
15721572 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+ }
15741576 DSUtils . deepMixIn ( options . params , params ) ;
15751577 }
15761578 return this . DEL (
@@ -1591,7 +1593,9 @@ function DSHttpAdapterProvider() {
15911593 options = options || { } ;
15921594 options . params = options . params || { } ;
15931595 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+ }
15951599 DSUtils . deepMixIn ( options . params , params ) ;
15961600 }
15971601 return this . GET (
@@ -1613,7 +1617,9 @@ function DSHttpAdapterProvider() {
16131617 options = options || { } ;
16141618 options . params = options . params || { } ;
16151619 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+ }
16171623 DSUtils . deepMixIn ( options . params , params ) ;
16181624 }
16191625 return this . PUT (
@@ -2182,7 +2188,7 @@ function find(resourceName, id, options) {
21822188 }
21832189 } , function ( err ) {
21842190 delete resource . pendingQueries [ id ] ;
2185- return err ;
2191+ return _this . $q . reject ( err ) ;
21862192 } ) ;
21872193 }
21882194
@@ -2212,12 +2218,11 @@ function processResults(utils, data, resourceName, queryHash) {
22122218 delete resource . pendingQueries [ queryHash ] ;
22132219 resource . completedQueries [ queryHash ] = new Date ( ) . getTime ( ) ;
22142220
2215- // Merge the new values into the cache
2216- this . inject ( resourceName , data ) ;
2217-
22182221 // Update modified timestamp of collection
22192222 resource . collectionModified = utils . updateTimestamp ( resource . collectionModified ) ;
2220- return data ;
2223+
2224+ // Merge the new values into the cache
2225+ return this . inject ( resourceName , data ) ;
22212226}
22222227
22232228function _findAll ( utils , resourceName , params , options ) {
@@ -2243,14 +2248,14 @@ function _findAll(utils, resourceName, params, options) {
22432248 try {
22442249 return processResults . apply ( _this , [ utils , data , resourceName , queryHash ] ) ;
22452250 } catch ( err ) {
2246- throw new _this . errors . UnhandledError ( err ) ;
2251+ return _this . $q . reject ( _this . errors . UnhandledError ( err ) ) ;
22472252 }
22482253 } else {
22492254 return data ;
22502255 }
22512256 } , function ( err ) {
22522257 delete resource . pendingQueries [ queryHash ] ;
2253- return err ;
2258+ return _this . $q . reject ( err ) ;
22542259 } ) ;
22552260 }
22562261
@@ -2302,7 +2307,7 @@ function _findAll(utils, resourceName, params, options) {
23022307 * ```
23032308 *
23042309 * @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:
23062311 *
23072312 * - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
23082313 * - `{object=}` - `where` - Where clause.
@@ -2332,6 +2337,7 @@ function findAll(resourceName, params, options) {
23322337 _this = this ;
23332338
23342339 options = options || { } ;
2340+ params = params || { } ;
23352341
23362342 if ( ! this . definitions [ resourceName ] ) {
23372343 deferred . reject ( new this . errors . RuntimeError ( errorPrefix + resourceName + ' is not a registered resource!' ) ) ;
@@ -4048,7 +4054,7 @@ var errorPrefix = 'DS.filter(resourceName, params[, options]): ';
40484054 * - `{UnhandledError}`
40494055 *
40504056 * @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:
40524058 *
40534059 * - `{object=}` - `query` - The query object by which to filter items of the type specified by `resourceName`. Properties:
40544060 * - `{object=}` - `where` - Where clause.
@@ -4065,7 +4071,7 @@ function filter(resourceName, params, options) {
40654071
40664072 if ( ! this . definitions [ resourceName ] ) {
40674073 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 ) ) {
40694075 throw new this . errors . IllegalArgumentError ( errorPrefix + 'params: Must be an object!' , { params : { actual : typeof params , expected : 'object' } } ) ;
40704076 } else if ( ! this . utils . isObject ( options ) ) {
40714077 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) {
40774083 _this = this ;
40784084
40794085 // Protect against null
4080- params . query = params . query || { } ;
4086+ params = params || { } ;
40814087
40824088 var queryHash = this . utils . toJson ( params ) ;
40834089
@@ -4090,6 +4096,7 @@ function filter(resourceName, params, options) {
40904096 }
40914097 }
40924098
4099+ params . query = params . query || { } ;
40934100 // The query has been completed, so hit the cache with the query
40944101 var filtered = this . utils . filter ( resource . collection , function ( attrs ) {
40954102 var keep = true ,
@@ -4220,13 +4227,14 @@ function get(resourceName, id, options) {
42204227 } else if ( ! this . utils . isObject ( options ) ) {
42214228 throw new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ;
42224229 }
4230+ var _this = this ;
42234231
42244232 try {
42254233 // cache miss, request resource from server
42264234 var item = this . store [ resourceName ] . index . get ( id ) ;
42274235 if ( ! item && options . loadFromServer ) {
42284236 this . find ( resourceName , id ) . then ( null , function ( err ) {
4229- throw err ;
4237+ return _this . $q . reject ( err ) ;
42304238 } ) ;
42314239 }
42324240
@@ -4470,9 +4478,11 @@ function _inject(definition, resource, attrs) {
44704478 }
44714479 }
44724480
4481+ var injected ;
44734482 if ( _this . utils . isArray ( attrs ) ) {
4483+ injected = [ ] ;
44744484 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 ] ) ) ;
44764486 }
44774487 } else {
44784488 if ( ! ( definition . idAttribute in attrs ) ) {
@@ -4517,12 +4527,14 @@ function _inject(definition, resource, attrs) {
45174527 }
45184528 resource . saved [ id ] = _this . utils . updateTimestamp ( resource . saved [ id ] ) ;
45194529 definition . afterInject ( definition . name , item ) ;
4530+ injected = item ;
45204531 } catch ( err ) {
45214532 $log . error ( err ) ;
45224533 $log . error ( 'inject failed!' , definition . name , attrs ) ;
45234534 }
45244535 }
45254536 }
4537+ return injected ;
45264538}
45274539
45284540/**
@@ -4586,18 +4598,15 @@ function inject(resourceName, attrs, options) {
45864598 _this = this ;
45874599
45884600 try {
4601+ var injected ;
45894602 if ( ! this . $rootScope . $$phase ) {
45904603 this . $rootScope . $apply ( function ( ) {
4591- _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4604+ injected = _inject . apply ( _this , [ definition , resource , attrs ] ) ;
45924605 } ) ;
45934606 } 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 ] ) ;
46004608 }
4609+ return injected ;
46014610 } catch ( err ) {
46024611 if ( ! ( err instanceof this . errors . RuntimeError ) ) {
46034612 throw new this . errors . UnhandledError ( err ) ;
@@ -4963,7 +4972,7 @@ module.exports = [function () {
49634972 * @id angular-data
49644973 * @name angular-data
49654974 * @description
4966- * __Version:__ 0.9.0
4975+ * __Version:__ 0.9.1
49674976 *
49684977 * ## Install
49694978 *
0 commit comments