@@ -1854,7 +1854,10 @@ var errorPrefix = 'DS.create(resourceName, attrs[, options]): ';
1854
1854
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
1855
1855
* @param {object } attrs The attributes with which to update the item of the type specified by `resourceName` that has
1856
1856
* the primary key specified by `id`.
1857
- * @param {object= } options Configuration options.
1857
+ * @param {object= } options Configuration options. Properties:
1858
+ *
1859
+ * - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
1860
+ *
1858
1861
* @returns {Promise } Promise produced by the `$q` service.
1859
1862
*
1860
1863
* ## Resolves with:
@@ -1882,6 +1885,10 @@ function create(resourceName, attrs, options) {
1882
1885
var resource = this . store [ resourceName ] ;
1883
1886
var _this = this ;
1884
1887
1888
+ if ( ! ( 'cacheResponse' in options ) ) {
1889
+ options . cacheResponse = true ;
1890
+ }
1891
+
1885
1892
promise = promise
1886
1893
. then ( function ( attrs ) {
1887
1894
return _this . $q . promisify ( definition . beforeValidate ) ( resourceName , attrs ) ;
@@ -1902,11 +1909,15 @@ function create(resourceName, attrs, options) {
1902
1909
return _this . $q . promisify ( definition . afterCreate ) ( resourceName , definition . deserialize ( resourceName , res ) ) ;
1903
1910
} )
1904
1911
. then ( function ( data ) {
1905
- var created = _this . inject ( definition . name , data ) ;
1906
- var id = created [ definition . idAttribute ] ;
1907
- resource . previousAttributes [ id ] = _this . utils . deepMixIn ( { } , created ) ;
1908
- resource . saved [ id ] = _this . utils . updateTimestamp ( resource . saved [ id ] ) ;
1909
- return _this . get ( definition . name , id ) ;
1912
+ if ( options . cacheResponse ) {
1913
+ var created = _this . inject ( definition . name , data ) ;
1914
+ var id = created [ definition . idAttribute ] ;
1915
+ resource . previousAttributes [ id ] = _this . utils . deepMixIn ( { } , created ) ;
1916
+ resource . saved [ id ] = _this . utils . updateTimestamp ( resource . saved [ id ] ) ;
1917
+ return _this . get ( definition . name , id ) ;
1918
+ } else {
1919
+ return data ;
1920
+ }
1910
1921
} ) ;
1911
1922
1912
1923
deferred . resolve ( attrs ) ;
@@ -2133,6 +2144,7 @@ var errorPrefix = 'DS.find(resourceName, id[, options]): ';
2133
2144
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
2134
2145
* @param {string|number } id The primary key of the item to retrieve.
2135
2146
* @param {object= } options Optional configuration. Properties:
2147
+ *
2136
2148
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
2137
2149
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
2138
2150
*
@@ -2166,8 +2178,6 @@ function find(resourceName, id, options) {
2166
2178
2167
2179
if ( ! ( 'cacheResponse' in options ) ) {
2168
2180
options . cacheResponse = true ;
2169
- } else {
2170
- options . cacheResponse = ! ! options . cacheResponse ;
2171
2181
}
2172
2182
2173
2183
var definition = this . definitions [ resourceName ] ;
@@ -2316,6 +2326,7 @@ function _findAll(utils, resourceName, params, options) {
2316
2326
* - `{string|array=}` - `orderBy` - OrderBy clause.
2317
2327
*
2318
2328
* @param {object= } options Optional configuration. Properties:
2329
+ *
2319
2330
* - `{boolean=}` - `bypassCache` - Bypass the cache. Default: `false`.
2320
2331
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
2321
2332
*
@@ -2351,8 +2362,6 @@ function findAll(resourceName, params, options) {
2351
2362
2352
2363
if ( ! ( 'cacheResponse' in options ) ) {
2353
2364
options . cacheResponse = true ;
2354
- } else {
2355
- options . cacheResponse = ! ! options . cacheResponse ;
2356
2365
}
2357
2366
2358
2367
promise = promise . then ( function ( ) {
@@ -2645,7 +2654,7 @@ var errorPrefix = 'DS.refresh(resourceName, id[, options]): ';
2645
2654
*
2646
2655
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
2647
2656
* @param {string|number } id The primary key of the item to refresh from the server.
2648
- * @param {object= } options Optional configuration. Properties:
2657
+ * @param {object= } options Optional configuration passed through to `DS.find` if it is called.
2649
2658
* @returns {false|Promise } `false` if the item doesn't already exist in the data store. A `Promise` if the item does
2650
2659
* exist in the data store and is being refreshed.
2651
2660
*
@@ -2712,7 +2721,9 @@ var errorPrefix = 'DS.save(resourceName, id[, options]): ';
2712
2721
*
2713
2722
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
2714
2723
* @param {string|number } id The primary key of the item to retrieve.
2715
- * @param {object= } options Optional configuration. Properties:
2724
+ * @param {object= } options Optional configuration. Properties::
2725
+ *
2726
+ * - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
2716
2727
* - `{boolean=}` - `changesOnly` - Only send changed and added values back to the server.
2717
2728
*
2718
2729
* @returns {Promise } Promise produced by the `$q` service.
@@ -2753,6 +2764,10 @@ function save(resourceName, id, options) {
2753
2764
var resource = this . store [ resourceName ] ;
2754
2765
var _this = this ;
2755
2766
2767
+ if ( ! ( 'cacheResponse' in options ) ) {
2768
+ options . cacheResponse = true ;
2769
+ }
2770
+
2756
2771
promise = promise
2757
2772
. then ( function ( attrs ) {
2758
2773
return _this . $q . promisify ( definition . beforeValidate ) ( resourceName , attrs ) ;
@@ -2792,10 +2807,14 @@ function save(resourceName, id, options) {
2792
2807
return _this . $q . promisify ( definition . afterUpdate ) ( resourceName , definition . deserialize ( resourceName , res ) ) ;
2793
2808
} )
2794
2809
. then ( function ( data ) {
2795
- _this . inject ( definition . name , data , options ) ;
2796
- resource . previousAttributes [ id ] = _this . utils . deepMixIn ( { } , data ) ;
2797
- resource . saved [ id ] = _this . utils . updateTimestamp ( resource . saved [ id ] ) ;
2798
- return _this . get ( resourceName , id ) ;
2810
+ if ( options . cacheResponse ) {
2811
+ var saved = _this . inject ( definition . name , data , options ) ;
2812
+ resource . previousAttributes [ id ] = _this . utils . deepMixIn ( { } , saved ) ;
2813
+ resource . saved [ id ] = _this . utils . updateTimestamp ( resource . saved [ id ] ) ;
2814
+ return _this . get ( resourceName , id ) ;
2815
+ } else {
2816
+ return data ;
2817
+ }
2799
2818
} ) ;
2800
2819
2801
2820
deferred . resolve ( item ) ;
@@ -2842,6 +2861,7 @@ var errorPrefix = 'DS.update(resourceName, id, attrs[, options]): ';
2842
2861
* @param {string|number } id The primary key of the item to update.
2843
2862
* @param {object } attrs The attributes with which to update the item.
2844
2863
* @param {object= } options Optional configuration. Properties:
2864
+ *
2845
2865
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
2846
2866
*
2847
2867
* @returns {Promise } Promise produced by the `$q` service.
@@ -2880,8 +2900,6 @@ function update(resourceName, id, attrs, options) {
2880
2900
2881
2901
if ( ! ( 'cacheResponse' in options ) ) {
2882
2902
options . cacheResponse = true ;
2883
- } else {
2884
- options . cacheResponse = ! ! options . cacheResponse ;
2885
2903
}
2886
2904
2887
2905
promise = promise
@@ -2973,6 +2991,7 @@ var errorPrefix = 'DS.updateAll(resourceName, attrs, params[, options]): ';
2973
2991
* - `{string|array=}` - `orderBy` - OrderBy clause.
2974
2992
*
2975
2993
* @param {object= } options Optional configuration. Properties:
2994
+ *
2976
2995
* - `{boolean=}` - `cacheResponse` - Inject the data returned by the server into the data store. Default: `true`.
2977
2996
*
2978
2997
* @returns {Promise } Promise produced by the `$q` service.
@@ -3010,8 +3029,6 @@ function updateAll(resourceName, attrs, params, options) {
3010
3029
3011
3030
if ( ! ( 'cacheResponse' in options ) ) {
3012
3031
options . cacheResponse = true ;
3013
- } else {
3014
- options . cacheResponse = ! ! options . cacheResponse ;
3015
3032
}
3016
3033
3017
3034
promise = promise
0 commit comments