@@ -2402,7 +2402,7 @@ function find(resourceName, id, options) {
2402
2402
var resource = this . store [ resourceName ] ;
2403
2403
var _this = this ;
2404
2404
2405
- if ( options . bypassCache ) {
2405
+ if ( options . bypassCache || ! options . cacheResponse ) {
2406
2406
delete resource . completedQueries [ id ] ;
2407
2407
}
2408
2408
@@ -2472,7 +2472,7 @@ function _findAll(utils, resourceName, params, options) {
2472
2472
_this = this ,
2473
2473
queryHash = utils . toJson ( params ) ;
2474
2474
2475
- if ( options . bypassCache ) {
2475
+ if ( options . bypassCache || ! options . cacheResponse ) {
2476
2476
delete resource . completedQueries [ queryHash ] ;
2477
2477
}
2478
2478
@@ -2861,17 +2861,19 @@ var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
2861
2861
*
2862
2862
* ```js
2863
2863
* // Exists in the data store, but we want a fresh copy
2864
- * DS.get('document', 'ee7f3f4d-98d5-4934-9e5a-6a559b08479f' );
2864
+ * DS.get('document', 5 );
2865
2865
*
2866
- * DS.refresh('document', 'ee7f3f4d-98d5-4934-9e5a-6a559b08479f' )
2866
+ * DS.refresh('document', 5 )
2867
2867
* .then(function (document) {
2868
2868
* document; // The fresh copy
2869
2869
* });
2870
2870
*
2871
2871
* // Does not exist in the data store
2872
- * DS.get('document', 'aab7ff66-e21e-46e2-8be8-264d82aee535');
2872
+ * DS.get('document', 6); // undefined
2873
2873
*
2874
- * DS.refresh('document', 'aab7ff66-e21e-46e2-8be8-264d82aee535'); // false
2874
+ * DS.refresh('document', 6).then(function (document) {
2875
+ * document; // undeinfed
2876
+ * }); // false
2875
2877
* ```
2876
2878
*
2877
2879
* ## Throws
@@ -2882,8 +2884,7 @@ var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
2882
2884
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
2883
2885
* @param {string|number } id The primary key of the item to refresh from the server.
2884
2886
* @param {object= } options Optional configuration passed through to `DS.find` if it is called.
2885
- * @returns {false|Promise } `false` if the item doesn't already exist in the data store. A `Promise` if the item does
2886
- * exist in the data store and is being refreshed.
2887
+ * @returns {Promise } A Promise created by the $q server.
2887
2888
*
2888
2889
* ## Resolves with:
2889
2890
*
@@ -2911,7 +2912,9 @@ function refresh(resourceName, id, options) {
2911
2912
if ( this . get ( resourceName , id ) ) {
2912
2913
return this . find ( resourceName , id , options ) ;
2913
2914
} else {
2914
- return false ;
2915
+ var deferred = this . $q . defer ( ) ;
2916
+ deferred . resolve ( ) ;
2917
+ return deferred . promise ;
2915
2918
}
2916
2919
}
2917
2920
}
@@ -4000,12 +4003,15 @@ function DSProvider() {
4000
4003
DSUtils . deepFreeze ( DS . errors ) ;
4001
4004
DSUtils . deepFreeze ( DS . utils ) ;
4002
4005
4003
- $rootScope . $watch ( function ( ) {
4004
- // Throttle angular-data's digest loop to tenths of a second
4005
- return new Date ( ) . getTime ( ) / 100 | 0 ;
4006
- } , function ( ) {
4007
- DS . digest ( ) ;
4008
- } ) ;
4006
+ if ( typeof Object . observe !== 'function' ||
4007
+ typeof Array . observe !== 'function' ) {
4008
+ $rootScope . $watch ( function ( ) {
4009
+ // Throttle angular-data's digest loop to tenths of a second
4010
+ return new Date ( ) . getTime ( ) / 100 | 0 ;
4011
+ } , function ( ) {
4012
+ DS . digest ( ) ;
4013
+ } ) ;
4014
+ }
4009
4015
4010
4016
return DS ;
4011
4017
}
@@ -4210,9 +4216,21 @@ function changes(resourceName, id) {
4210
4216
}
4211
4217
4212
4218
var item = this . get ( resourceName , id ) ;
4219
+ var _this = this ;
4220
+
4213
4221
if ( item ) {
4214
4222
this . store [ resourceName ] . observers [ id ] . deliver ( ) ;
4215
- return this . utils . diffObjectFromOldObject ( item , this . store [ resourceName ] . previousAttributes [ id ] ) ;
4223
+ var diff = this . utils . diffObjectFromOldObject ( item , this . store [ resourceName ] . previousAttributes [ id ] ) ;
4224
+ this . utils . forOwn ( diff , function ( changeset , name ) {
4225
+ var toKeep = [ ] ;
4226
+ _this . utils . forOwn ( changeset , function ( value , field ) {
4227
+ if ( ! angular . isFunction ( value ) ) {
4228
+ toKeep . push ( field ) ;
4229
+ }
4230
+ } ) ;
4231
+ diff [ name ] = _this . utils . pick ( diff [ name ] , toKeep ) ;
4232
+ } ) ;
4233
+ return diff ;
4216
4234
}
4217
4235
}
4218
4236
@@ -4455,23 +4473,30 @@ function defineResource(definition) {
4455
4473
// Prepare for computed properties
4456
4474
if ( def . computed ) {
4457
4475
DS . utils . forOwn ( def . computed , function ( fn , field ) {
4476
+ if ( angular . isFunction ( fn ) ) {
4477
+ def . computed [ field ] = [ fn ] ;
4478
+ fn = def . computed [ field ] ;
4479
+ }
4458
4480
if ( def . methods && field in def . methods ) {
4459
4481
DS . $log . warn ( errorPrefix + 'Computed property "' + field + '" conflicts with previously defined prototype method!' ) ;
4460
4482
}
4461
4483
var deps ;
4462
- if ( angular . isFunction ( fn ) ) {
4463
- var match = fn . toString ( ) . match ( / f u n c t i o n .* ?\( ( [ \s \S ] * ?) \) / ) ;
4484
+ if ( fn . length === 1 ) {
4485
+ var match = fn [ 0 ] . toString ( ) . match ( / f u n c t i o n .* ?\( ( [ \s \S ] * ?) \) / ) ;
4464
4486
deps = match [ 1 ] . split ( ',' ) ;
4465
- DS . $log . warn ( errorPrefix + 'Use the computed property array for compatibility with minified code!' ) ;
4466
- } else {
4467
- deps = fn . slice ( 0 , fn . length - 1 ) ;
4487
+ def . computed [ field ] = deps . concat ( fn ) ;
4488
+ fn = def . computed [ field ] ;
4489
+ if ( deps . length ) {
4490
+ DS . $log . warn ( errorPrefix + 'Use the computed property array syntax for compatibility with minified code!' ) ;
4491
+ }
4468
4492
}
4493
+ deps = fn . slice ( 0 , fn . length - 1 ) ;
4494
+ angular . forEach ( deps , function ( val , index ) {
4495
+ deps [ index ] = val . trim ( ) ;
4496
+ } ) ;
4469
4497
fn . deps = DS . utils . filter ( deps , function ( dep ) {
4470
4498
return ! ! dep ;
4471
4499
} ) ;
4472
- angular . forEach ( fn . deps , function ( val , index ) {
4473
- fn . deps [ index ] = val . trim ( ) ;
4474
- } ) ;
4475
4500
} ) ;
4476
4501
}
4477
4502
@@ -5120,17 +5145,14 @@ function _inject(definition, resource, attrs) {
5120
5145
compute = true ;
5121
5146
}
5122
5147
} ) ;
5148
+ compute = compute || ! fn . deps . length ;
5123
5149
if ( compute ) {
5124
5150
var args = [ ] ;
5125
5151
angular . forEach ( fn . deps , function ( dep ) {
5126
5152
args . push ( item [ dep ] ) ;
5127
5153
} ) ;
5128
5154
// recompute property
5129
- if ( angular . isFunction ( fn ) ) {
5130
- item [ field ] = fn . apply ( item , args ) ;
5131
- } else {
5132
- item [ field ] = fn [ fn . length - 1 ] . apply ( item , args ) ;
5133
- }
5155
+ item [ field ] = fn [ fn . length - 1 ] . apply ( item , args ) ;
5134
5156
}
5135
5157
} ) ;
5136
5158
}
@@ -5150,21 +5172,23 @@ function _inject(definition, resource, attrs) {
5150
5172
}
5151
5173
} else {
5152
5174
// check if "idAttribute" is a computed property
5153
- if ( definition . computed && definition . computed [ definition . idAttribute ] ) {
5175
+ var c = definition . computed ;
5176
+ var idA = definition . idAttribute ;
5177
+ if ( c && c [ idA ] ) {
5154
5178
var args = [ ] ;
5155
- angular . forEach ( definition . computed [ definition . idAttribute ] . deps , function ( dep ) {
5179
+ angular . forEach ( c [ idA ] . deps , function ( dep ) {
5156
5180
args . push ( attrs [ dep ] ) ;
5157
5181
} ) ;
5158
- attrs [ definition . idAttribute ] = definition . computed [ definition . idAttribute ] . apply ( attrs , args ) ;
5182
+ attrs [ idA ] = c [ idA ] [ c [ idA ] . length - 1 ] . apply ( attrs , args ) ;
5159
5183
}
5160
- if ( ! ( definition . idAttribute in attrs ) ) {
5184
+ if ( ! ( idA in attrs ) ) {
5161
5185
var error = new _this . errors . R ( errorPrefix + 'attrs: Must contain the property specified by `idAttribute`!' ) ;
5162
5186
$log . error ( error ) ;
5163
5187
throw error ;
5164
5188
} else {
5165
5189
try {
5166
5190
definition . beforeInject ( definition . name , attrs ) ;
5167
- var id = attrs [ definition . idAttribute ] ;
5191
+ var id = attrs [ idA ] ;
5168
5192
var item = this . get ( definition . name , id ) ;
5169
5193
5170
5194
if ( ! item ) {
0 commit comments