@@ -20,6 +20,7 @@ define([
20
20
method : 'GET' ,
21
21
dataType : 'json'
22
22
} ,
23
+ dataScope : '' ,
23
24
data : { }
24
25
} ,
25
26
@@ -29,8 +30,16 @@ define([
29
30
* @returns {DataStorage } Chainable.
30
31
*/
31
32
initConfig : function ( ) {
33
+ var scope ;
34
+
32
35
this . _super ( ) ;
33
36
37
+ scope = this . dataScope ;
38
+
39
+ if ( typeof scope === 'string' ) {
40
+ this . dataScope = scope ? [ scope ] : [ ] ;
41
+ }
42
+
34
43
this . _requests = [ ] ;
35
44
36
45
return this ;
@@ -77,10 +86,12 @@ define([
77
86
* @returns {jQueryPromise }
78
87
*/
79
88
getData : function ( params , options ) {
80
- var cachedRequest = this . getRequest ( params ) ;
89
+ var cachedRequest ;
81
90
82
- if ( params && params . filters && params . filters [ 'store_id' ] ) {
83
- cachedRequest = false ;
91
+ if ( this . hasScopeChanged ( params ) ) {
92
+ this . clearRequests ( ) ;
93
+ } else {
94
+ cachedRequest = this . getRequest ( params ) ;
84
95
}
85
96
86
97
options = options || { } ;
@@ -90,6 +101,30 @@ define([
90
101
this . requestData ( params ) ;
91
102
} ,
92
103
104
+ /**
105
+ * Tells whether one of the parameters defined in the "dataScope" has
106
+ * changed since the last request.
107
+ *
108
+ * @param {Object } params - Request parameters.
109
+ * @returns {Boolean }
110
+ */
111
+ hasScopeChanged : function ( params ) {
112
+ var lastRequest = _ . last ( this . _requests ) ,
113
+ keys ,
114
+ diff ;
115
+
116
+ if ( ! lastRequest ) {
117
+ return false ;
118
+ }
119
+
120
+ diff = utils . compare ( lastRequest . params , params ) ;
121
+
122
+ keys = _ . pluck ( diff . changes , 'path' ) ;
123
+ keys = keys . concat ( Object . keys ( diff . containers ) ) ;
124
+
125
+ return _ . intersection ( this . dataScope , keys ) . length > 0 ;
126
+ } ,
127
+
93
128
/**
94
129
* Extends records of current data object
95
130
* with the provided records collection.
0 commit comments