11/**
22 * @author Jason Dobry <jason.dobry@gmail.com>
33 * @file angular-data.js
4- * @version 0.4.1 - Homepage <http://jmdobry.github.io/angular-data/>
4+ * @version 0.4.2 - Homepage <http://jmdobry.github.io/angular-data/>
55 * @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/angular-data>
66 * @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
77 *
@@ -2071,28 +2071,22 @@ function processResults(data, resourceName, queryHash) {
20712071 delete resource . pendingQueries [ queryHash ] ;
20722072 resource . completedQueries [ queryHash ] = new Date ( ) . getTime ( ) ;
20732073
2074- var temp = [ ] ;
2074+ // Merge the new values into the cache
20752075 for ( var i = 0 ; i < data . length ; i ++ ) {
2076- temp . push ( data [ i ] ) ;
2076+ this . inject ( resourceName , data [ i ] ) ;
20772077 }
2078- // Merge the new values into the cache
2079- resource . collection = utils . mergeArrays ( resource . collection , data , resource . idAttribute || 'id' ) ;
20802078
20812079 // Update the data store's index for this resource
2082- resource . index = utils . toLookup ( resource . collection , resource . idAttribute || 'id' ) ;
2083-
2084- // Update modified timestamp for values that were return by the server
2085- for ( var j = 0 ; j < temp . length ; j ++ ) {
2086- resource . modified [ temp [ j ] [ resource . idAttribute || 'id' ] ] = utils . updateTimestamp ( resource . modified [ temp [ j ] [ resource . idAttribute || 'id' ] ] ) ;
2087- }
2080+ resource . index = utils . toLookup ( resource . collection , resource . idAttribute || services . config . idAttribute || 'id' ) ;
20882081
20892082 // Update modified timestamp of collection
20902083 resource . collectionModified = utils . updateTimestamp ( resource . collectionModified ) ;
2091- return temp ;
2084+ return data ;
20922085}
20932086
20942087function _findAll ( deferred , resourceName , params , options ) {
2095- var resource = services . store [ resourceName ] ;
2088+ var resource = services . store [ resourceName ] ,
2089+ _this = this ;
20962090
20972091 var queryHash = utils . toJson ( params ) ;
20982092
@@ -2109,7 +2103,7 @@ function _findAll(deferred, resourceName, params, options) {
21092103 var url = utils . makePath ( resource . baseUrl || services . config . baseUrl , resource . endpoint || resource . name ) ;
21102104 resource . pendingQueries [ queryHash ] = GET ( url , { params : params } ) . then ( function ( data ) {
21112105 try {
2112- deferred . resolve ( processResults ( data , resourceName , queryHash ) ) ;
2106+ deferred . resolve ( processResults . apply ( _this , [ data , resourceName , queryHash ] ) ) ;
21132107 } catch ( err ) {
21142108 deferred . reject ( new errors . UnhandledError ( err ) ) ;
21152109 }
@@ -2787,16 +2781,16 @@ function DSProvider() {
27872781
27882782module . exports = DSProvider ;
27892783
2790- } , { "./async_methods" :31 , "./http" :34 , "./sync_methods" :45 , "errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , "cX8q+p" :[ function ( require , module , exports ) {
2784+ } , { "./async_methods" :31 , "./http" :34 , "./sync_methods" :45 , "errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , "services" :[ function ( require , module , exports ) {
2785+ module . exports = require ( 'cX8q+p' ) ;
2786+ } , { } ] , "cX8q+p" :[ function ( require , module , exports ) {
27912787module . exports = {
27922788 config : {
27932789 idAttribute : 'id'
27942790 } ,
27952791 store : { }
27962792} ;
27972793
2798- } , { } ] , "services" :[ function ( require , module , exports ) {
2799- module . exports = require ( 'cX8q+p' ) ;
28002794} , { } ] , 38 :[ function ( require , module , exports ) {
28012795var utils = require ( 'utils' ) ,
28022796 errors = require ( 'errors' ) ,
@@ -3532,12 +3526,7 @@ function _inject(resource, attrs) {
35323526 resource . changes [ innerId ] = utils . diffObjectFromOldObject ( resource . index [ innerId ] , resource . previous_attributes [ innerId ] ) ;
35333527 resource . modified [ innerId ] = utils . updateTimestamp ( resource . modified [ innerId ] ) ;
35343528 resource . collectionModified = utils . updateTimestamp ( resource . collectionModified ) ;
3535-
3536- services . $log . debug ( 'old value:' , JSON . stringify ( resource . previous_attributes [ innerId ] , null , 2 ) ) ;
3537- services . $log . debug ( 'changes:' , resource . changes [ innerId ] ) ;
3538- services . $log . debug ( 'new value:' , JSON . stringify ( resource . index [ innerId ] , null , 2 ) ) ;
35393529 } catch ( err ) {
3540- services . $log . error ( err . stack ) ;
35413530 throw new errors . UnhandledError ( err ) ;
35423531 }
35433532 } ) ;
@@ -4105,19 +4094,6 @@ module.exports = {
41054094 return newTimestamp ;
41064095 }
41074096 } ,
4108- mergeArrays : function ( a , b , mergeKey ) {
4109- mergeKey = mergeKey || 'id' ;
4110- for ( var i = 0 ; i < a . length ; i ++ ) {
4111- for ( var j = 0 ; j < b . length ; j ++ ) {
4112- if ( a [ i ] [ mergeKey ] == b [ j ] [ mergeKey ] ) {
4113- angular . extend ( a [ i ] , b [ j ] ) ;
4114- b . splice ( j , 1 ) ;
4115- break ;
4116- }
4117- }
4118- }
4119- return a . concat ( b ) ;
4120- } ,
41214097 deepFreeze : function deepFreeze ( o ) {
41224098 if ( typeof Object . freeze === 'function' ) {
41234099 var prop , propKey ;
0 commit comments