@@ -2402,7 +2402,7 @@ function find(resourceName, id, options) {
24022402 var resource = this . store [ resourceName ] ;
24032403 var _this = this ;
24042404
2405- if ( options . bypassCache ) {
2405+ if ( options . bypassCache || ! options . cacheResponse ) {
24062406 delete resource . completedQueries [ id ] ;
24072407 }
24082408
@@ -2472,7 +2472,7 @@ function _findAll(utils, resourceName, params, options) {
24722472 _this = this ,
24732473 queryHash = utils . toJson ( params ) ;
24742474
2475- if ( options . bypassCache ) {
2475+ if ( options . bypassCache || ! options . cacheResponse ) {
24762476 delete resource . completedQueries [ queryHash ] ;
24772477 }
24782478
@@ -2861,17 +2861,19 @@ var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
28612861 *
28622862 * ```js
28632863 * // 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 );
28652865 *
2866- * DS.refresh('document', 'ee7f3f4d-98d5-4934-9e5a-6a559b08479f' )
2866+ * DS.refresh('document', 5 )
28672867 * .then(function (document) {
28682868 * document; // The fresh copy
28692869 * });
28702870 *
28712871 * // Does not exist in the data store
2872- * DS.get('document', 'aab7ff66-e21e-46e2-8be8-264d82aee535');
2872+ * DS.get('document', 6); // undefined
28732873 *
2874- * DS.refresh('document', 'aab7ff66-e21e-46e2-8be8-264d82aee535'); // false
2874+ * DS.refresh('document', 6).then(function (document) {
2875+ * document; // undeinfed
2876+ * }); // false
28752877 * ```
28762878 *
28772879 * ## Throws
@@ -2882,8 +2884,7 @@ var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
28822884 * @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
28832885 * @param {string|number } id The primary key of the item to refresh from the server.
28842886 * @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.
28872888 *
28882889 * ## Resolves with:
28892890 *
@@ -2911,7 +2912,9 @@ function refresh(resourceName, id, options) {
29112912 if ( this . get ( resourceName , id ) ) {
29122913 return this . find ( resourceName , id , options ) ;
29132914 } else {
2914- return false ;
2915+ var deferred = this . $q . defer ( ) ;
2916+ deferred . resolve ( ) ;
2917+ return deferred . promise ;
29152918 }
29162919 }
29172920}
@@ -4000,12 +4003,15 @@ function DSProvider() {
40004003 DSUtils . deepFreeze ( DS . errors ) ;
40014004 DSUtils . deepFreeze ( DS . utils ) ;
40024005
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+ }
40094015
40104016 return DS ;
40114017 }
@@ -4210,9 +4216,21 @@ function changes(resourceName, id) {
42104216 }
42114217
42124218 var item = this . get ( resourceName , id ) ;
4219+ var _this = this ;
4220+
42134221 if ( item ) {
42144222 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 ;
42164234 }
42174235}
42184236
@@ -4455,23 +4473,30 @@ function defineResource(definition) {
44554473 // Prepare for computed properties
44564474 if ( def . computed ) {
44574475 DS . utils . forOwn ( def . computed , function ( fn , field ) {
4476+ if ( angular . isFunction ( fn ) ) {
4477+ def . computed [ field ] = [ fn ] ;
4478+ fn = def . computed [ field ] ;
4479+ }
44584480 if ( def . methods && field in def . methods ) {
44594481 DS . $log . warn ( errorPrefix + 'Computed property "' + field + '" conflicts with previously defined prototype method!' ) ;
44604482 }
44614483 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 ] * ?) \) / ) ;
44644486 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+ }
44684492 }
4493+ deps = fn . slice ( 0 , fn . length - 1 ) ;
4494+ angular . forEach ( deps , function ( val , index ) {
4495+ deps [ index ] = val . trim ( ) ;
4496+ } ) ;
44694497 fn . deps = DS . utils . filter ( deps , function ( dep ) {
44704498 return ! ! dep ;
44714499 } ) ;
4472- angular . forEach ( fn . deps , function ( val , index ) {
4473- fn . deps [ index ] = val . trim ( ) ;
4474- } ) ;
44754500 } ) ;
44764501 }
44774502
@@ -5120,17 +5145,14 @@ function _inject(definition, resource, attrs) {
51205145 compute = true ;
51215146 }
51225147 } ) ;
5148+ compute = compute || ! fn . deps . length ;
51235149 if ( compute ) {
51245150 var args = [ ] ;
51255151 angular . forEach ( fn . deps , function ( dep ) {
51265152 args . push ( item [ dep ] ) ;
51275153 } ) ;
51285154 // 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 ) ;
51345156 }
51355157 } ) ;
51365158 }
@@ -5150,21 +5172,23 @@ function _inject(definition, resource, attrs) {
51505172 }
51515173 } else {
51525174 // 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 ] ) {
51545178 var args = [ ] ;
5155- angular . forEach ( definition . computed [ definition . idAttribute ] . deps , function ( dep ) {
5179+ angular . forEach ( c [ idA ] . deps , function ( dep ) {
51565180 args . push ( attrs [ dep ] ) ;
51575181 } ) ;
5158- attrs [ definition . idAttribute ] = definition . computed [ definition . idAttribute ] . apply ( attrs , args ) ;
5182+ attrs [ idA ] = c [ idA ] [ c [ idA ] . length - 1 ] . apply ( attrs , args ) ;
51595183 }
5160- if ( ! ( definition . idAttribute in attrs ) ) {
5184+ if ( ! ( idA in attrs ) ) {
51615185 var error = new _this . errors . R ( errorPrefix + 'attrs: Must contain the property specified by `idAttribute`!' ) ;
51625186 $log . error ( error ) ;
51635187 throw error ;
51645188 } else {
51655189 try {
51665190 definition . beforeInject ( definition . name , attrs ) ;
5167- var id = attrs [ definition . idAttribute ] ;
5191+ var id = attrs [ idA ] ;
51685192 var item = this . get ( definition . name , id ) ;
51695193
51705194 if ( ! item ) {
0 commit comments