@khanacademy/wonder-blocks-data 2.3.0 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.js +495 -892
- package/dist/index.js +783 -1071
- package/package.json +6 -5
- package/src/components/data.js +4 -6
- package/src/components/intercept-context.js +2 -3
- package/src/util/memory-cache.js +2 -1
- package/src/util/no-cache.js +2 -1
- package/src/util/request-handler.js +2 -1
- package/src/util/request-tracking.js +2 -3
- package/src/__tests__/index.test.js +0 -147
package/dist/index.js
CHANGED
|
@@ -82,7 +82,7 @@ module.exports =
|
|
|
82
82
|
/******/
|
|
83
83
|
/******/
|
|
84
84
|
/******/ // Load entry module and return exports
|
|
85
|
-
/******/ return __webpack_require__(__webpack_require__.s =
|
|
85
|
+
/******/ return __webpack_require__(__webpack_require__.s = 14);
|
|
86
86
|
/******/ })
|
|
87
87
|
/************************************************************************/
|
|
88
88
|
/******/ ([
|
|
@@ -93,272 +93,14 @@ module.exports = require("react");
|
|
|
93
93
|
|
|
94
94
|
/***/ }),
|
|
95
95
|
/* 1 */
|
|
96
|
-
/***/ (function(module, exports) {
|
|
97
|
-
|
|
98
|
-
module.exports = require("@khanacademy/wonder-blocks-core");
|
|
99
|
-
|
|
100
|
-
/***/ }),
|
|
101
|
-
/* 2 */
|
|
102
96
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
103
97
|
|
|
104
98
|
"use strict";
|
|
105
|
-
|
|
106
|
-
__webpack_require__
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
__webpack_require__.d(__webpack_exports__, "fulfillAllDataRequests", function() { return /* binding */ src_fulfillAllDataRequests; });
|
|
111
|
-
__webpack_require__.d(__webpack_exports__, "hasUnfulfilledRequests", function() { return /* binding */ src_hasUnfulfilledRequests; });
|
|
112
|
-
__webpack_require__.d(__webpack_exports__, "removeFromCache", function() { return /* binding */ src_removeFromCache; });
|
|
113
|
-
__webpack_require__.d(__webpack_exports__, "removeAllFromCache", function() { return /* binding */ src_removeAllFromCache; });
|
|
114
|
-
__webpack_require__.d(__webpack_exports__, "RequestHandler", function() { return /* reexport */ RequestHandler; });
|
|
115
|
-
__webpack_require__.d(__webpack_exports__, "TrackData", function() { return /* reexport */ track_data_TrackData; });
|
|
116
|
-
__webpack_require__.d(__webpack_exports__, "Data", function() { return /* reexport */ data_Data; });
|
|
117
|
-
__webpack_require__.d(__webpack_exports__, "InterceptData", function() { return /* reexport */ intercept_data_InterceptData; });
|
|
118
|
-
__webpack_require__.d(__webpack_exports__, "InterceptCache", function() { return /* reexport */ intercept_cache_InterceptCache; });
|
|
119
|
-
__webpack_require__.d(__webpack_exports__, "NoCache", function() { return /* reexport */ NoCache; });
|
|
120
|
-
|
|
121
|
-
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-core"
|
|
122
|
-
var wonder_blocks_core_ = __webpack_require__(1);
|
|
123
|
-
|
|
124
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/util/memory-cache.js
|
|
125
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
126
|
-
|
|
127
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
128
|
-
|
|
129
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
130
|
-
|
|
131
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
132
|
-
|
|
133
|
-
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
134
|
-
|
|
135
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
136
|
-
|
|
137
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
138
|
-
|
|
139
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
140
|
-
|
|
141
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
142
|
-
|
|
143
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
144
|
-
|
|
145
|
-
function deepClone(source) {
|
|
146
|
-
/**
|
|
147
|
-
* We want to deep clone the source cache to dodge mutations by external
|
|
148
|
-
* references. So we serialize the source cache to JSON and parse it
|
|
149
|
-
* back into a new object.
|
|
150
|
-
*
|
|
151
|
-
* NOTE: This doesn't work for get/set property accessors.
|
|
152
|
-
*/
|
|
153
|
-
var serializedInitCache = JSON.stringify(source);
|
|
154
|
-
var cloneInitCache = JSON.parse(serializedInitCache);
|
|
155
|
-
return Object.freeze(cloneInitCache);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* INTERNAL USE ONLY
|
|
159
|
-
*
|
|
160
|
-
* Special case cache implementation for the memory cache.
|
|
161
|
-
*
|
|
162
|
-
* This is only used within our framework. Handlers don't need to
|
|
163
|
-
* provide this as a custom cache as the framework will default to this in the
|
|
164
|
-
* absence of a custom cache. We use this for SSR too (see ./response-cache.js).
|
|
165
|
-
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
var MemoryCache = /*#__PURE__*/function () {
|
|
169
|
-
function MemoryCache() {
|
|
170
|
-
var _this = this;
|
|
171
|
-
|
|
172
|
-
var source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
173
|
-
|
|
174
|
-
_classCallCheck(this, MemoryCache);
|
|
175
|
-
|
|
176
|
-
_defineProperty(this, "_cache", void 0);
|
|
177
|
-
|
|
178
|
-
_defineProperty(this, "store", function (handler, options, entry) {
|
|
179
|
-
var requestType = handler.type;
|
|
180
|
-
var frozenEntry = Object.isFrozen(entry) ? entry : Object.freeze(entry); // Ensure we have a cache location for this handler type.
|
|
181
|
-
|
|
182
|
-
_this._cache[requestType] = _this._cache[requestType] || {}; // Cache the data.
|
|
183
|
-
|
|
184
|
-
var key = handler.getKey(options);
|
|
185
|
-
_this._cache[requestType][key] = frozenEntry;
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
_defineProperty(this, "retrieve", function (handler, options) {
|
|
189
|
-
var requestType = handler.type; // Get the internal subcache for the handler.
|
|
190
|
-
|
|
191
|
-
var handlerCache = _this._cache[requestType];
|
|
192
|
-
|
|
193
|
-
if (!handlerCache) {
|
|
194
|
-
return null;
|
|
195
|
-
} // Get the response.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var key = handler.getKey(options);
|
|
199
|
-
var internalEntry = handlerCache[key];
|
|
200
|
-
|
|
201
|
-
if (internalEntry == null) {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return internalEntry;
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
_defineProperty(this, "remove", function (handler, options) {
|
|
209
|
-
var requestType = handler.type; // NOTE(somewhatabstract): We could invoke removeAll with a predicate
|
|
210
|
-
// to match the key of the entry we're removing, but that's an
|
|
211
|
-
// inefficient way to remove a single item, so let's not do that.
|
|
212
|
-
// Get the internal subcache for the handler.
|
|
213
|
-
|
|
214
|
-
var handlerCache = _this._cache[requestType];
|
|
215
|
-
|
|
216
|
-
if (!handlerCache) {
|
|
217
|
-
return false;
|
|
218
|
-
} // Get the entry.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
var key = handler.getKey(options);
|
|
222
|
-
var internalEntry = handlerCache[key];
|
|
223
|
-
|
|
224
|
-
if (internalEntry == null) {
|
|
225
|
-
return false;
|
|
226
|
-
} // Delete the entry.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
delete handlerCache[key];
|
|
230
|
-
return true;
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
_defineProperty(this, "removeAll", function (handler, predicate) {
|
|
234
|
-
var requestType = handler.type; // Get the internal subcache for the handler.
|
|
235
|
-
|
|
236
|
-
var handlerCache = _this._cache[requestType];
|
|
237
|
-
|
|
238
|
-
if (!handlerCache) {
|
|
239
|
-
return 0;
|
|
240
|
-
} // Apply the predicate to what we have cached.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
var removedCount = 0;
|
|
244
|
-
|
|
245
|
-
for (var _i = 0, _Object$entries = Object.entries(handlerCache); _i < _Object$entries.length; _i++) {
|
|
246
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
247
|
-
_key = _Object$entries$_i[0],
|
|
248
|
-
_entry = _Object$entries$_i[1];
|
|
249
|
-
|
|
250
|
-
if (typeof predicate !== "function" || predicate(_key, _entry)) {
|
|
251
|
-
removedCount++;
|
|
252
|
-
delete handlerCache[_key];
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return removedCount;
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
_defineProperty(this, "cloneData", function () {
|
|
260
|
-
try {
|
|
261
|
-
return deepClone(_this._cache);
|
|
262
|
-
} catch (e) {
|
|
263
|
-
throw new Error("An error occurred while trying to clone the cache: ".concat(e));
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
this._cache = {};
|
|
268
|
-
|
|
269
|
-
if (source != null) {
|
|
270
|
-
try {
|
|
271
|
-
/**
|
|
272
|
-
* Object.assign only performs a shallow clone.
|
|
273
|
-
* So we deep clone it and then assign the clone values to our
|
|
274
|
-
* internal cache.
|
|
275
|
-
*/
|
|
276
|
-
var cloneInitCache = deepClone(source);
|
|
277
|
-
Object.assign(this._cache, cloneInitCache);
|
|
278
|
-
} catch (e) {
|
|
279
|
-
throw new Error("An error occurred trying to initialize from a response cache snapshot: ".concat(e));
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
_createClass(MemoryCache, [{
|
|
285
|
-
key: "inUse",
|
|
286
|
-
get: function get() {
|
|
287
|
-
return Object.keys(this._cache).length > 0;
|
|
288
|
-
}
|
|
289
|
-
}]);
|
|
290
|
-
|
|
291
|
-
return MemoryCache;
|
|
292
|
-
}();
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/util/no-cache.js
|
|
296
|
-
function no_cache_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
297
|
-
|
|
298
|
-
function no_cache_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
299
|
-
|
|
300
|
-
function no_cache_createClass(Constructor, protoProps, staticProps) { if (protoProps) no_cache_defineProperties(Constructor.prototype, protoProps); if (staticProps) no_cache_defineProperties(Constructor, staticProps); return Constructor; }
|
|
301
|
-
|
|
302
|
-
function no_cache_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
303
|
-
|
|
304
|
-
var defaultInstance = null;
|
|
305
|
-
/**
|
|
306
|
-
* This is a cache implementation to use when no caching is wanted.
|
|
307
|
-
*
|
|
308
|
-
* Use this with your request handler if you want to support server-side
|
|
309
|
-
* rendering of your data requests, but want to ensure data is never cached
|
|
310
|
-
* on the client-side.
|
|
311
|
-
*
|
|
312
|
-
* This is better than having `shouldRefreshCache` always return `true` in the
|
|
313
|
-
* handler as this ensures that cache space and memory are never used for the
|
|
314
|
-
* requested data after hydration has finished.
|
|
315
|
-
*/
|
|
316
|
-
|
|
317
|
-
var NoCache = /*#__PURE__*/function () {
|
|
318
|
-
function NoCache() {
|
|
319
|
-
no_cache_classCallCheck(this, NoCache);
|
|
320
|
-
|
|
321
|
-
no_cache_defineProperty(this, "store", function (handler, options, entry) {
|
|
322
|
-
/* empty */
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
no_cache_defineProperty(this, "retrieve", function (handler, options) {
|
|
326
|
-
return null;
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
no_cache_defineProperty(this, "remove", function (handler, options) {
|
|
330
|
-
return false;
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
no_cache_defineProperty(this, "removeAll", function (handler, predicate) {
|
|
334
|
-
return 0;
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
no_cache_createClass(NoCache, null, [{
|
|
339
|
-
key: "Default",
|
|
340
|
-
get: function get() {
|
|
341
|
-
if (defaultInstance == null) {
|
|
342
|
-
defaultInstance = new NoCache();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return defaultInstance;
|
|
346
|
-
}
|
|
347
|
-
}]);
|
|
348
|
-
|
|
349
|
-
return NoCache;
|
|
350
|
-
}();
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/util/response-cache.js
|
|
354
|
-
function response_cache_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
355
|
-
|
|
356
|
-
function response_cache_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
357
|
-
|
|
358
|
-
function response_cache_createClass(Constructor, protoProps, staticProps) { if (protoProps) response_cache_defineProperties(Constructor.prototype, protoProps); if (staticProps) response_cache_defineProperties(Constructor, staticProps); return Constructor; }
|
|
359
|
-
|
|
360
|
-
function response_cache_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
361
|
-
|
|
99
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ResponseCache; });
|
|
100
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
|
101
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
|
|
102
|
+
/* harmony import */ var _memory_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
|
|
103
|
+
/* harmony import */ var _no_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5);
|
|
362
104
|
|
|
363
105
|
|
|
364
106
|
|
|
@@ -367,7 +109,7 @@ function response_cache_defineProperty(obj, key, value) { if (key in obj) { Obje
|
|
|
367
109
|
* The default instance is stored here.
|
|
368
110
|
* It's created below in the Default() static property.
|
|
369
111
|
*/
|
|
370
|
-
|
|
112
|
+
let _default;
|
|
371
113
|
/**
|
|
372
114
|
* Implements the response cache.
|
|
373
115
|
*
|
|
@@ -375,60 +117,46 @@ var _default;
|
|
|
375
117
|
*/
|
|
376
118
|
|
|
377
119
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (!_default) {
|
|
383
|
-
_default = new ResponseCache();
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return _default;
|
|
120
|
+
class ResponseCache {
|
|
121
|
+
static get Default() {
|
|
122
|
+
if (!_default) {
|
|
123
|
+
_default = new ResponseCache();
|
|
387
124
|
}
|
|
388
|
-
}]);
|
|
389
|
-
|
|
390
|
-
function ResponseCache() {
|
|
391
|
-
var _this = this;
|
|
392
|
-
|
|
393
|
-
var memoryCache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
394
|
-
var ssrOnlyCache = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
395
125
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
response_cache_defineProperty(this, "_hydrationAndDefaultCache", void 0);
|
|
399
|
-
|
|
400
|
-
response_cache_defineProperty(this, "_ssrOnlyCache", void 0);
|
|
126
|
+
return _default;
|
|
127
|
+
}
|
|
401
128
|
|
|
402
|
-
|
|
403
|
-
|
|
129
|
+
constructor(memoryCache = null, ssrOnlyCache = null) {
|
|
130
|
+
this.initialize = source => {
|
|
131
|
+
if (this._hydrationAndDefaultCache.inUse) {
|
|
404
132
|
throw new Error("Cannot initialize data response cache more than once");
|
|
405
133
|
}
|
|
406
134
|
|
|
407
135
|
try {
|
|
408
|
-
|
|
136
|
+
this._hydrationAndDefaultCache = new _memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"](source);
|
|
409
137
|
} catch (e) {
|
|
410
|
-
throw new Error(
|
|
138
|
+
throw new Error(`An error occurred trying to initialize the data response cache: ${e}`);
|
|
411
139
|
}
|
|
412
|
-
}
|
|
140
|
+
};
|
|
413
141
|
|
|
414
|
-
|
|
415
|
-
return
|
|
416
|
-
data
|
|
142
|
+
this.cacheData = (handler, options, data) => {
|
|
143
|
+
return this._setCacheEntry(handler, options, {
|
|
144
|
+
data
|
|
417
145
|
});
|
|
418
|
-
}
|
|
146
|
+
};
|
|
419
147
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return
|
|
148
|
+
this.cacheError = (handler, options, error) => {
|
|
149
|
+
const errorMessage = typeof error === "string" ? error : error.message;
|
|
150
|
+
return this._setCacheEntry(handler, options, {
|
|
423
151
|
error: errorMessage
|
|
424
152
|
});
|
|
425
|
-
}
|
|
153
|
+
};
|
|
426
154
|
|
|
427
|
-
|
|
155
|
+
this.getEntry = (handler, options) => {
|
|
428
156
|
// If we're not server-side, and the handler has a custom cache
|
|
429
157
|
// let's try to use it.
|
|
430
|
-
if (
|
|
431
|
-
|
|
158
|
+
if (this._ssrOnlyCache == null && handler.cache != null) {
|
|
159
|
+
const entry = handler.cache.retrieve(handler, options);
|
|
432
160
|
|
|
433
161
|
if (entry != null) {
|
|
434
162
|
// Custom cache has an entry, so use it.
|
|
@@ -440,12 +168,12 @@ var response_cache_ResponseCache = /*#__PURE__*/function () {
|
|
|
440
168
|
// we would never hydrate properly.
|
|
441
169
|
|
|
442
170
|
|
|
443
|
-
|
|
171
|
+
const internalEntry = this._defaultCache(handler).retrieve(handler, options); // If we are not server-side and we hydrated something that the custom
|
|
444
172
|
// cache didn't have, we need to make sure the custom cache contains
|
|
445
173
|
// that value.
|
|
446
174
|
|
|
447
175
|
|
|
448
|
-
if (
|
|
176
|
+
if (this._ssrOnlyCache == null && handler.cache != null && internalEntry != null) {
|
|
449
177
|
// Yes, if this throws, we will have a problem. We want that.
|
|
450
178
|
// Bad cache implementations should be overt.
|
|
451
179
|
handler.cache.store(handler, options, internalEntry); // We now delete this from our in-memory cache as we don't need it.
|
|
@@ -454,208 +182,111 @@ var response_cache_ResponseCache = /*#__PURE__*/function () {
|
|
|
454
182
|
// expected valid usage of this framework - two handlers with
|
|
455
183
|
// different caching options shouldn't be using the same type name.
|
|
456
184
|
|
|
457
|
-
|
|
185
|
+
this._hydrationAndDefaultCache.remove(handler, options);
|
|
458
186
|
}
|
|
459
187
|
|
|
460
188
|
return internalEntry;
|
|
461
|
-
}
|
|
189
|
+
};
|
|
462
190
|
|
|
463
|
-
|
|
191
|
+
this.remove = (handler, options) => {
|
|
464
192
|
// NOTE(somewhatabstract): We could invoke removeAll with a predicate
|
|
465
193
|
// to match the key of the entry we're removing, but that's an
|
|
466
194
|
// inefficient way to remove a single item, so let's not do that.
|
|
467
195
|
// If we're not server-side, and the handler has a custom cache
|
|
468
196
|
// let's try to use it.
|
|
469
|
-
|
|
470
|
-
|
|
197
|
+
const customCache = this._ssrOnlyCache == null ? handler.cache : null;
|
|
198
|
+
const removedCustom = !!(customCache != null && customCache.remove(handler, options)); // Delete the entry from our internal cache.
|
|
471
199
|
// Even if we have a custom cache, we want to make sure we still
|
|
472
200
|
// removed the same value from internal cache since this could be
|
|
473
201
|
// getting called before hydration for some complex advanced usage
|
|
474
202
|
// reason.
|
|
475
203
|
|
|
476
|
-
return
|
|
477
|
-
}
|
|
204
|
+
return this._defaultCache(handler).remove(handler, options) || removedCustom;
|
|
205
|
+
};
|
|
478
206
|
|
|
479
|
-
|
|
207
|
+
this.removeAll = (handler, predicate) => {
|
|
480
208
|
// If we're not server-side, and the handler has a custom cache
|
|
481
209
|
// let's try to use it.
|
|
482
|
-
|
|
483
|
-
|
|
210
|
+
const customCache = this._ssrOnlyCache == null ? handler.cache : null;
|
|
211
|
+
const removedCountCustom = (customCache == null ? void 0 : customCache.removeAll(handler, predicate)) || 0; // Apply the predicate to what we have in our internal cached.
|
|
484
212
|
// Even if we have a custom cache, we want to make sure we still
|
|
485
213
|
// removed the same value from internal cache since this could be
|
|
486
214
|
// getting called before hydration for some complex advanced usage
|
|
487
215
|
// reason.
|
|
488
216
|
|
|
489
|
-
|
|
217
|
+
const removedCount = this._defaultCache(handler).removeAll(handler, predicate); // We have no idea which keys were removed from which caches,
|
|
490
218
|
// so we can't dedupe the remove counts based on keys.
|
|
491
219
|
// That's why we return the total records deleted rather than the
|
|
492
220
|
// total keys deleted.
|
|
493
221
|
|
|
494
222
|
|
|
495
223
|
return removedCount + removedCountCustom;
|
|
496
|
-
}
|
|
224
|
+
};
|
|
497
225
|
|
|
498
|
-
|
|
226
|
+
this.cloneHydratableData = () => {
|
|
499
227
|
// We return our hydration cache only.
|
|
500
|
-
return
|
|
501
|
-
}
|
|
228
|
+
return this._hydrationAndDefaultCache.cloneData();
|
|
229
|
+
};
|
|
502
230
|
|
|
503
|
-
this._ssrOnlyCache =
|
|
504
|
-
this._hydrationAndDefaultCache = memoryCache || new
|
|
231
|
+
this._ssrOnlyCache = _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() ? ssrOnlyCache || new _memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"]() : undefined;
|
|
232
|
+
this._hydrationAndDefaultCache = memoryCache || new _memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"]();
|
|
505
233
|
}
|
|
506
234
|
/**
|
|
507
235
|
* Returns the default cache to use for the given handler.
|
|
508
236
|
*/
|
|
509
237
|
|
|
510
238
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
} // If the handler doesn't want to hydrate, we return the SSR-only cache.
|
|
517
|
-
// If we are client-side, we return our non-caching implementation.
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
return this._ssrOnlyCache || NoCache.Default;
|
|
521
|
-
}
|
|
522
|
-
}, {
|
|
523
|
-
key: "_setCacheEntry",
|
|
524
|
-
value: function _setCacheEntry(handler, options, entry) {
|
|
525
|
-
var frozenEntry = Object.freeze(entry);
|
|
526
|
-
|
|
527
|
-
if (this._ssrOnlyCache == null && handler.cache != null) {
|
|
528
|
-
// We are not server-side, and our handler has its own cache,
|
|
529
|
-
// so we use that to store values.
|
|
530
|
-
handler.cache.store(handler, options, frozenEntry);
|
|
531
|
-
} else {
|
|
532
|
-
// We are either server-side, or our handler doesn't provide
|
|
533
|
-
// a caching override.
|
|
534
|
-
this._defaultCache(handler).store(handler, options, frozenEntry);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
return frozenEntry;
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Initialize the cache from a given cache state.
|
|
541
|
-
*
|
|
542
|
-
* This can only be called if the cache is not already in use.
|
|
543
|
-
*/
|
|
544
|
-
|
|
545
|
-
}]);
|
|
546
|
-
|
|
547
|
-
return ResponseCache;
|
|
548
|
-
}();
|
|
549
|
-
// EXTERNAL MODULE: external "react"
|
|
550
|
-
var external_react_ = __webpack_require__(0);
|
|
239
|
+
_defaultCache(handler) {
|
|
240
|
+
if (handler.hydrate) {
|
|
241
|
+
return this._hydrationAndDefaultCache;
|
|
242
|
+
} // If the handler doesn't want to hydrate, we return the SSR-only cache.
|
|
243
|
+
// If we are client-side, we return our non-caching implementation.
|
|
551
244
|
|
|
552
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/util/request-fulfillment.js
|
|
553
|
-
function request_fulfillment_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
554
245
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
function request_fulfillment_createClass(Constructor, protoProps, staticProps) { if (protoProps) request_fulfillment_defineProperties(Constructor.prototype, protoProps); if (staticProps) request_fulfillment_defineProperties(Constructor, staticProps); return Constructor; }
|
|
558
|
-
|
|
559
|
-
function request_fulfillment_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
var request_fulfillment_default;
|
|
564
|
-
|
|
565
|
-
var request_fulfillment_RequestFulfillment = /*#__PURE__*/function () {
|
|
566
|
-
request_fulfillment_createClass(RequestFulfillment, null, [{
|
|
567
|
-
key: "Default",
|
|
568
|
-
get: function get() {
|
|
569
|
-
if (!request_fulfillment_default) {
|
|
570
|
-
request_fulfillment_default = new RequestFulfillment();
|
|
571
|
-
}
|
|
246
|
+
return this._ssrOnlyCache || _no_cache_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"].Default;
|
|
247
|
+
}
|
|
572
248
|
|
|
573
|
-
|
|
249
|
+
_setCacheEntry(handler, options, entry) {
|
|
250
|
+
const frozenEntry = Object.freeze(entry);
|
|
251
|
+
|
|
252
|
+
if (this._ssrOnlyCache == null && handler.cache != null) {
|
|
253
|
+
// We are not server-side, and our handler has its own cache,
|
|
254
|
+
// so we use that to store values.
|
|
255
|
+
handler.cache.store(handler, options, frozenEntry);
|
|
256
|
+
} else {
|
|
257
|
+
// We are either server-side, or our handler doesn't provide
|
|
258
|
+
// a caching override.
|
|
259
|
+
this._defaultCache(handler).store(handler, options, frozenEntry);
|
|
574
260
|
}
|
|
575
|
-
}]);
|
|
576
|
-
|
|
577
|
-
function RequestFulfillment() {
|
|
578
|
-
var _this = this;
|
|
579
|
-
|
|
580
|
-
var responseCache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
|
581
|
-
|
|
582
|
-
request_fulfillment_classCallCheck(this, RequestFulfillment);
|
|
583
|
-
|
|
584
|
-
request_fulfillment_defineProperty(this, "_responseCache", void 0);
|
|
585
|
-
|
|
586
|
-
request_fulfillment_defineProperty(this, "_requests", {});
|
|
587
|
-
|
|
588
|
-
request_fulfillment_defineProperty(this, "_getHandlerSubcache", function (handler) {
|
|
589
|
-
if (!_this._requests[handler.type]) {
|
|
590
|
-
_this._requests[handler.type] = {};
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
return _this._requests[handler.type];
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
request_fulfillment_defineProperty(this, "fulfill", function (handler, options) {
|
|
597
|
-
var handlerRequests = _this._getHandlerSubcache(handler);
|
|
598
|
-
|
|
599
|
-
var key = handler.getKey(options);
|
|
600
|
-
/**
|
|
601
|
-
* If we have an inflight request, we'll provide that.
|
|
602
|
-
*/
|
|
603
|
-
|
|
604
|
-
var inflight = handlerRequests[key];
|
|
605
|
-
|
|
606
|
-
if (inflight) {
|
|
607
|
-
return inflight;
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* We don't have an inflight request, so let's set one up.
|
|
611
|
-
*/
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
var _this$_responseCache = _this._responseCache,
|
|
615
|
-
cacheData = _this$_responseCache.cacheData,
|
|
616
|
-
cacheError = _this$_responseCache.cacheError;
|
|
617
|
-
|
|
618
|
-
try {
|
|
619
|
-
var request = handler.fulfillRequest(options).then(function (data) {
|
|
620
|
-
delete handlerRequests[key];
|
|
621
|
-
/**
|
|
622
|
-
* Let's cache the data!
|
|
623
|
-
*/
|
|
624
|
-
|
|
625
|
-
return cacheData(handler, options, data);
|
|
626
|
-
}).catch(function (error) {
|
|
627
|
-
delete handlerRequests[key];
|
|
628
|
-
/**
|
|
629
|
-
* Let's cache the error!
|
|
630
|
-
*/
|
|
631
|
-
|
|
632
|
-
return cacheError(handler, options, error);
|
|
633
|
-
});
|
|
634
|
-
handlerRequests[key] = request;
|
|
635
|
-
return request;
|
|
636
|
-
} catch (e) {
|
|
637
|
-
/**
|
|
638
|
-
* In this case, we don't cache an inflight request, because there
|
|
639
|
-
* really isn't one.
|
|
640
|
-
*/
|
|
641
|
-
return Promise.resolve(cacheError(handler, options, e));
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
261
|
|
|
645
|
-
|
|
262
|
+
return frozenEntry;
|
|
646
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Initialize the cache from a given cache state.
|
|
266
|
+
*
|
|
267
|
+
* This can only be called if the cache is not already in use.
|
|
268
|
+
*/
|
|
647
269
|
|
|
648
|
-
return RequestFulfillment;
|
|
649
|
-
}();
|
|
650
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/util/request-tracking.js
|
|
651
|
-
function request_tracking_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
652
270
|
|
|
653
|
-
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/***/ }),
|
|
274
|
+
/* 2 */
|
|
275
|
+
/***/ (function(module, exports) {
|
|
654
276
|
|
|
655
|
-
|
|
277
|
+
module.exports = require("@khanacademy/wonder-blocks-core");
|
|
656
278
|
|
|
657
|
-
|
|
279
|
+
/***/ }),
|
|
280
|
+
/* 3 */
|
|
281
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
658
282
|
|
|
283
|
+
"use strict";
|
|
284
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return TrackerContext; });
|
|
285
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestTracker; });
|
|
286
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
287
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
288
|
+
/* harmony import */ var _response_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
|
|
289
|
+
/* harmony import */ var _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
|
|
659
290
|
|
|
660
291
|
|
|
661
292
|
|
|
@@ -665,13 +296,13 @@ function request_tracking_defineProperty(obj, key, value) { if (key in obj) { Ob
|
|
|
665
296
|
*
|
|
666
297
|
* INTERNAL USE ONLY
|
|
667
298
|
*/
|
|
668
|
-
|
|
299
|
+
const TrackerContext = new react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
|
|
669
300
|
/**
|
|
670
301
|
* The default instance is stored here.
|
|
671
302
|
* It's created below in the Default() static property.
|
|
672
303
|
*/
|
|
673
304
|
|
|
674
|
-
|
|
305
|
+
let _default;
|
|
675
306
|
/**
|
|
676
307
|
* Implements request tracking and fulfillment.
|
|
677
308
|
*
|
|
@@ -679,76 +310,59 @@ var request_tracking_default;
|
|
|
679
310
|
*/
|
|
680
311
|
|
|
681
312
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
if (!request_tracking_default) {
|
|
687
|
-
request_tracking_default = new RequestTracker();
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
return request_tracking_default;
|
|
313
|
+
class RequestTracker {
|
|
314
|
+
static get Default() {
|
|
315
|
+
if (!_default) {
|
|
316
|
+
_default = new RequestTracker();
|
|
691
317
|
}
|
|
692
|
-
/**
|
|
693
|
-
* These are the caches for tracked requests, their handlers, and responses.
|
|
694
|
-
*/
|
|
695
|
-
|
|
696
|
-
}]);
|
|
697
|
-
|
|
698
|
-
function RequestTracker() {
|
|
699
|
-
var _this = this;
|
|
700
|
-
|
|
701
|
-
var responseCache = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
|
702
|
-
|
|
703
|
-
request_tracking_classCallCheck(this, RequestTracker);
|
|
704
318
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
319
|
+
return _default;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* These are the caches for tracked requests, their handlers, and responses.
|
|
323
|
+
*/
|
|
708
324
|
|
|
709
|
-
request_tracking_defineProperty(this, "_responseCache", void 0);
|
|
710
325
|
|
|
711
|
-
|
|
326
|
+
constructor(responseCache = undefined) {
|
|
327
|
+
this._trackedHandlers = {};
|
|
328
|
+
this._trackedRequests = {};
|
|
712
329
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
330
|
+
this.trackDataRequest = (handler, options) => {
|
|
331
|
+
const key = handler.getKey(options);
|
|
332
|
+
const type = handler.type;
|
|
716
333
|
/**
|
|
717
334
|
* Make sure we have stored the handler for use when fulfilling requests.
|
|
718
335
|
*/
|
|
719
336
|
|
|
720
|
-
if (
|
|
721
|
-
|
|
722
|
-
|
|
337
|
+
if (this._trackedHandlers[type] == null) {
|
|
338
|
+
this._trackedHandlers[type] = handler;
|
|
339
|
+
this._trackedRequests[type] = {};
|
|
723
340
|
}
|
|
724
341
|
/**
|
|
725
342
|
* If we don't already have this tracked, then let's track it.
|
|
726
343
|
*/
|
|
727
344
|
|
|
728
345
|
|
|
729
|
-
if (
|
|
730
|
-
|
|
346
|
+
if (this._trackedRequests[type][key] == null) {
|
|
347
|
+
this._trackedRequests[type][key] = options;
|
|
731
348
|
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
request_tracking_defineProperty(this, "reset", function () {
|
|
735
|
-
_this._trackedHandlers = {};
|
|
736
|
-
_this._trackedRequests = {};
|
|
737
|
-
});
|
|
349
|
+
};
|
|
738
350
|
|
|
739
|
-
|
|
740
|
-
|
|
351
|
+
this.reset = () => {
|
|
352
|
+
this._trackedHandlers = {};
|
|
353
|
+
this._trackedRequests = {};
|
|
354
|
+
};
|
|
741
355
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
var _handler = _this._trackedHandlers[_handlerType]; // For each handler, we will perform the request fulfillments!
|
|
356
|
+
this.fulfillTrackedRequests = () => {
|
|
357
|
+
const promises = [];
|
|
745
358
|
|
|
746
|
-
|
|
359
|
+
for (const handlerType of Object.keys(this._trackedHandlers)) {
|
|
360
|
+
const handler = this._trackedHandlers[handlerType]; // For each handler, we will perform the request fulfillments!
|
|
747
361
|
|
|
748
|
-
|
|
749
|
-
var requestKey = _Object$keys2[_i2];
|
|
362
|
+
const requests = this._trackedRequests[handlerType];
|
|
750
363
|
|
|
751
|
-
|
|
364
|
+
for (const requestKey of Object.keys(requests)) {
|
|
365
|
+
const promise = this._requestFulfillment.fulfill(handler, requests[requestKey]);
|
|
752
366
|
|
|
753
367
|
promises.push(promise);
|
|
754
368
|
}
|
|
@@ -772,19 +386,16 @@ var request_tracking_RequestTracker = /*#__PURE__*/function () {
|
|
|
772
386
|
*/
|
|
773
387
|
|
|
774
388
|
|
|
775
|
-
|
|
389
|
+
this.reset();
|
|
776
390
|
/**
|
|
777
391
|
* Let's wait for everything to fulfill, and then clone the cached data.
|
|
778
392
|
*/
|
|
779
393
|
|
|
394
|
+
return Promise.all(promises).then(() => this._responseCache.cloneHydratableData());
|
|
395
|
+
};
|
|
780
396
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
});
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
this._responseCache = responseCache || response_cache_ResponseCache.Default;
|
|
787
|
-
this._requestFulfillment = new request_fulfillment_RequestFulfillment(responseCache);
|
|
397
|
+
this._responseCache = responseCache || _response_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseCache */ "a"].Default;
|
|
398
|
+
this._requestFulfillment = new _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestFulfillment */ "a"](responseCache);
|
|
788
399
|
}
|
|
789
400
|
/**
|
|
790
401
|
* Track a request.
|
|
@@ -794,578 +405,509 @@ var request_tracking_RequestTracker = /*#__PURE__*/function () {
|
|
|
794
405
|
*/
|
|
795
406
|
|
|
796
407
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
* @returns {Promise<Cache>} A frozen cache of the data that was cached
|
|
817
|
-
* as a result of fulfilling the tracked requests.
|
|
818
|
-
*/
|
|
408
|
+
/**
|
|
409
|
+
* Indicates if we have requests waiting to be fulfilled.
|
|
410
|
+
*/
|
|
411
|
+
get hasUnfulfilledRequests() {
|
|
412
|
+
return Object.keys(this._trackedRequests).length > 0;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Initiate fulfillment of all tracked requests.
|
|
416
|
+
*
|
|
417
|
+
* This loops over the requests that were tracked using TrackData, and asks
|
|
418
|
+
* the respective handlers to fulfill those requests in the order they were
|
|
419
|
+
* tracked.
|
|
420
|
+
*
|
|
421
|
+
* Calling this method marks tracked requests as fulfilled; requests are
|
|
422
|
+
* removed from the list of tracked requests by calling this method.
|
|
423
|
+
*
|
|
424
|
+
* @returns {Promise<Cache>} A frozen cache of the data that was cached
|
|
425
|
+
* as a result of fulfilling the tracked requests.
|
|
426
|
+
*/
|
|
819
427
|
|
|
820
|
-
}]);
|
|
821
428
|
|
|
822
|
-
|
|
823
|
-
}();
|
|
824
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/util/request-handler.js
|
|
825
|
-
function request_handler_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
429
|
+
}
|
|
826
430
|
|
|
827
|
-
|
|
431
|
+
/***/ }),
|
|
432
|
+
/* 4 */
|
|
433
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
828
434
|
|
|
829
|
-
|
|
435
|
+
"use strict";
|
|
436
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
437
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
830
438
|
|
|
831
|
-
function request_handler_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
832
439
|
|
|
833
440
|
/**
|
|
834
|
-
*
|
|
441
|
+
* InterceptContext defines a map from handler type to interception methods.
|
|
835
442
|
*
|
|
836
|
-
*
|
|
837
|
-
* use with the Wonder Blocks Data framework.
|
|
443
|
+
* INTERNAL USE ONLY
|
|
838
444
|
*/
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
var hydrate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
842
|
-
|
|
843
|
-
request_handler_classCallCheck(this, RequestHandler);
|
|
844
|
-
|
|
845
|
-
request_handler_defineProperty(this, "_type", void 0);
|
|
846
|
-
|
|
847
|
-
request_handler_defineProperty(this, "_cache", void 0);
|
|
848
|
-
|
|
849
|
-
request_handler_defineProperty(this, "_hydrate", void 0);
|
|
850
|
-
|
|
851
|
-
this._type = type;
|
|
852
|
-
this._cache = cache || null;
|
|
853
|
-
this._hydrate = !!hydrate;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
request_handler_createClass(RequestHandler, [{
|
|
857
|
-
key: "shouldRefreshCache",
|
|
858
|
-
value: function shouldRefreshCache(options, cachedEntry) {
|
|
859
|
-
/**
|
|
860
|
-
* By default, the cache needs a refresh if the current entry is an
|
|
861
|
-
* error.
|
|
862
|
-
*
|
|
863
|
-
* This means that an error will cause a re-request on render.
|
|
864
|
-
* Useful if the server rendered an error, as it means the client
|
|
865
|
-
* will update after rehydration.
|
|
866
|
-
*/
|
|
867
|
-
return cachedEntry == null || cachedEntry.error != null;
|
|
868
|
-
}
|
|
869
|
-
}, {
|
|
870
|
-
key: "getKey",
|
|
871
|
-
value: function getKey(options) {
|
|
872
|
-
try {
|
|
873
|
-
return options === undefined ? "undefined" : JSON.stringify(options);
|
|
874
|
-
} catch (e) {
|
|
875
|
-
throw new Error("Failed to auto-generate key: ".concat(e));
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}, {
|
|
879
|
-
key: "fulfillRequest",
|
|
880
|
-
value: function fulfillRequest(options) {
|
|
881
|
-
throw new Error("Not implemented");
|
|
882
|
-
}
|
|
883
|
-
}, {
|
|
884
|
-
key: "type",
|
|
885
|
-
get: function get() {
|
|
886
|
-
return this._type;
|
|
887
|
-
}
|
|
888
|
-
}, {
|
|
889
|
-
key: "cache",
|
|
890
|
-
get: function get() {
|
|
891
|
-
return this._cache;
|
|
892
|
-
}
|
|
893
|
-
}, {
|
|
894
|
-
key: "hydrate",
|
|
895
|
-
get: function get() {
|
|
896
|
-
return this._hydrate;
|
|
897
|
-
}
|
|
898
|
-
}]);
|
|
899
|
-
|
|
900
|
-
return RequestHandler;
|
|
901
|
-
}();
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/components/track-data.js
|
|
905
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
906
|
-
|
|
907
|
-
function track_data_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
908
|
-
|
|
909
|
-
function track_data_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
910
|
-
|
|
911
|
-
function track_data_createClass(Constructor, protoProps, staticProps) { if (protoProps) track_data_defineProperties(Constructor.prototype, protoProps); if (staticProps) track_data_defineProperties(Constructor, staticProps); return Constructor; }
|
|
912
|
-
|
|
913
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
914
|
-
|
|
915
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
916
|
-
|
|
917
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
918
|
-
|
|
919
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
920
|
-
|
|
921
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
922
|
-
|
|
923
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
924
|
-
|
|
925
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
445
|
+
const InterceptContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"]({});
|
|
446
|
+
/* harmony default export */ __webpack_exports__["a"] = (InterceptContext);
|
|
929
447
|
|
|
448
|
+
/***/ }),
|
|
449
|
+
/* 5 */
|
|
450
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
930
451
|
|
|
452
|
+
"use strict";
|
|
453
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return NoCache; });
|
|
454
|
+
let defaultInstance = null;
|
|
931
455
|
/**
|
|
932
|
-
*
|
|
456
|
+
* This is a cache implementation to use when no caching is wanted.
|
|
457
|
+
*
|
|
458
|
+
* Use this with your request handler if you want to support server-side
|
|
459
|
+
* rendering of your data requests, but want to ensure data is never cached
|
|
460
|
+
* on the client-side.
|
|
461
|
+
*
|
|
462
|
+
* This is better than having `shouldRefreshCache` always return `true` in the
|
|
463
|
+
* handler as this ensures that cache space and memory are never used for the
|
|
464
|
+
* requested data after hydration has finished.
|
|
933
465
|
*/
|
|
934
|
-
var track_data_TrackData = /*#__PURE__*/function (_React$Component) {
|
|
935
|
-
_inherits(TrackData, _React$Component);
|
|
936
466
|
|
|
937
|
-
|
|
467
|
+
class NoCache {
|
|
468
|
+
constructor() {
|
|
469
|
+
this.store = (handler, options, entry) => {
|
|
470
|
+
/* empty */
|
|
471
|
+
};
|
|
938
472
|
|
|
939
|
-
|
|
940
|
-
track_data_classCallCheck(this, TrackData);
|
|
473
|
+
this.retrieve = (handler, options) => null;
|
|
941
474
|
|
|
942
|
-
|
|
943
|
-
}
|
|
475
|
+
this.remove = (handler, options) => false;
|
|
944
476
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
value: function render() {
|
|
948
|
-
if (!wonder_blocks_core_["Server"].isServerSide()) {
|
|
949
|
-
throw new Error("This component is not for use during client-side rendering");
|
|
950
|
-
}
|
|
477
|
+
this.removeAll = (handler, predicate) => 0;
|
|
478
|
+
}
|
|
951
479
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
480
|
+
static get Default() {
|
|
481
|
+
if (defaultInstance == null) {
|
|
482
|
+
defaultInstance = new NoCache();
|
|
955
483
|
}
|
|
956
|
-
}]);
|
|
957
|
-
|
|
958
|
-
return TrackData;
|
|
959
|
-
}(external_react_["Component"]);
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/components/internal-data.js
|
|
963
|
-
function internal_data_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { internal_data_typeof = function _typeof(obj) { return typeof obj; }; } else { internal_data_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return internal_data_typeof(obj); }
|
|
964
|
-
|
|
965
|
-
function internal_data_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
966
|
-
|
|
967
|
-
function internal_data_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
968
|
-
|
|
969
|
-
function internal_data_createClass(Constructor, protoProps, staticProps) { if (protoProps) internal_data_defineProperties(Constructor.prototype, protoProps); if (staticProps) internal_data_defineProperties(Constructor, staticProps); return Constructor; }
|
|
970
|
-
|
|
971
|
-
function internal_data_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) internal_data_setPrototypeOf(subClass, superClass); }
|
|
972
|
-
|
|
973
|
-
function internal_data_setPrototypeOf(o, p) { internal_data_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return internal_data_setPrototypeOf(o, p); }
|
|
974
|
-
|
|
975
|
-
function internal_data_createSuper(Derived) { var hasNativeReflectConstruct = internal_data_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = internal_data_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = internal_data_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return internal_data_possibleConstructorReturn(this, result); }; }
|
|
976
|
-
|
|
977
|
-
function internal_data_possibleConstructorReturn(self, call) { if (call && (internal_data_typeof(call) === "object" || typeof call === "function")) { return call; } return internal_data_assertThisInitialized(self); }
|
|
978
|
-
|
|
979
|
-
function internal_data_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
980
|
-
|
|
981
|
-
function internal_data_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
982
|
-
|
|
983
|
-
function internal_data_getPrototypeOf(o) { internal_data_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return internal_data_getPrototypeOf(o); }
|
|
984
|
-
|
|
985
|
-
function internal_data_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
986
484
|
|
|
485
|
+
return defaultInstance;
|
|
486
|
+
}
|
|
987
487
|
|
|
488
|
+
}
|
|
988
489
|
|
|
490
|
+
/***/ }),
|
|
491
|
+
/* 6 */
|
|
492
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
989
493
|
|
|
494
|
+
"use strict";
|
|
495
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestFulfillment; });
|
|
496
|
+
/* harmony import */ var _response_cache_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
|
990
497
|
|
|
991
498
|
|
|
992
|
-
|
|
993
|
-
* This component is responsible for actually handling the data request.
|
|
994
|
-
* It is wrapped by Data in order to support intercepts and be exported for use.
|
|
995
|
-
*
|
|
996
|
-
* INTERNAL USE ONLY
|
|
997
|
-
*/
|
|
998
|
-
var internal_data_InternalData = /*#__PURE__*/function (_React$Component) {
|
|
999
|
-
internal_data_inherits(InternalData, _React$Component);
|
|
499
|
+
let _default;
|
|
1000
500
|
|
|
1001
|
-
|
|
501
|
+
class RequestFulfillment {
|
|
502
|
+
static get Default() {
|
|
503
|
+
if (!_default) {
|
|
504
|
+
_default = new RequestFulfillment();
|
|
505
|
+
}
|
|
1002
506
|
|
|
1003
|
-
|
|
1004
|
-
|
|
507
|
+
return _default;
|
|
508
|
+
}
|
|
1005
509
|
|
|
1006
|
-
|
|
510
|
+
constructor(responseCache = undefined) {
|
|
511
|
+
this._requests = {};
|
|
1007
512
|
|
|
1008
|
-
|
|
513
|
+
this._getHandlerSubcache = handler => {
|
|
514
|
+
if (!this._requests[handler.type]) {
|
|
515
|
+
this._requests[handler.type] = {};
|
|
516
|
+
}
|
|
1009
517
|
|
|
1010
|
-
|
|
518
|
+
return this._requests[handler.type];
|
|
519
|
+
};
|
|
1011
520
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
}
|
|
521
|
+
this.fulfill = (handler, options) => {
|
|
522
|
+
const handlerRequests = this._getHandlerSubcache(handler);
|
|
1015
523
|
|
|
1016
|
-
|
|
1017
|
-
key: "componentDidMount",
|
|
1018
|
-
value: function componentDidMount() {
|
|
1019
|
-
this._mounted = true;
|
|
1020
|
-
}
|
|
1021
|
-
}, {
|
|
1022
|
-
key: "shouldComponentUpdate",
|
|
1023
|
-
value: function shouldComponentUpdate(nextProps, nextState) {
|
|
524
|
+
const key = handler.getKey(options);
|
|
1024
525
|
/**
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
* And we only update the state if props changed
|
|
1028
|
-
* or we got new data/error.
|
|
526
|
+
* If we have an inflight request, we'll provide that.
|
|
1029
527
|
*/
|
|
1030
|
-
if (!this._propsMatch(nextProps)) {
|
|
1031
|
-
var newState = this._buildStateAndfulfillNeeds(nextProps);
|
|
1032
528
|
|
|
1033
|
-
|
|
529
|
+
const inflight = handlerRequests[key];
|
|
530
|
+
|
|
531
|
+
if (inflight) {
|
|
532
|
+
return inflight;
|
|
1034
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* We don't have an inflight request, so let's set one up.
|
|
536
|
+
*/
|
|
1035
537
|
|
|
1036
|
-
return this.state.loading !== nextState.loading || this.state.data !== nextState.data || this.state.error !== nextState.error;
|
|
1037
|
-
}
|
|
1038
|
-
}, {
|
|
1039
|
-
key: "componentWillUnmount",
|
|
1040
|
-
value: function componentWillUnmount() {
|
|
1041
|
-
this._mounted = false;
|
|
1042
|
-
}
|
|
1043
|
-
}, {
|
|
1044
|
-
key: "_propsMatch",
|
|
1045
|
-
value: function _propsMatch(otherProps) {
|
|
1046
|
-
var _this$props = this.props,
|
|
1047
|
-
handler = _this$props.handler,
|
|
1048
|
-
options = _this$props.options;
|
|
1049
|
-
var prevHandler = otherProps.handler,
|
|
1050
|
-
prevOptions = otherProps.options;
|
|
1051
|
-
return handler === prevHandler && handler.getKey(options) === prevHandler.getKey(prevOptions);
|
|
1052
|
-
}
|
|
1053
|
-
}, {
|
|
1054
|
-
key: "_buildStateAndfulfillNeeds",
|
|
1055
|
-
value: function _buildStateAndfulfillNeeds(propsAtFulfillment) {
|
|
1056
|
-
var _this2 = this;
|
|
1057
538
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
539
|
+
const {
|
|
540
|
+
cacheData,
|
|
541
|
+
cacheError
|
|
542
|
+
} = this._responseCache;
|
|
1062
543
|
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
* we should refresh the cache.
|
|
1067
|
-
*
|
|
1068
|
-
* Therefore, we need to request data.
|
|
1069
|
-
*
|
|
1070
|
-
* We have to do this here from the constructor so that this
|
|
1071
|
-
* data request is tracked when performing server-side rendering.
|
|
1072
|
-
*/
|
|
1073
|
-
request_fulfillment_RequestFulfillment.Default.fulfill(handler, options).then(function (cacheEntry) {
|
|
544
|
+
try {
|
|
545
|
+
const request = handler.fulfillRequest(options).then(data => {
|
|
546
|
+
delete handlerRequests[key];
|
|
1074
547
|
/**
|
|
1075
|
-
*
|
|
1076
|
-
* However, we need to update the component, but we
|
|
1077
|
-
* should only do that if the props are the same as they
|
|
1078
|
-
* were when this was called.
|
|
548
|
+
* Let's cache the data!
|
|
1079
549
|
*/
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
error: cacheEntry.error
|
|
1085
|
-
});
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
return null;
|
|
1089
|
-
}).catch(function (e) {
|
|
550
|
+
|
|
551
|
+
return cacheData(handler, options, data);
|
|
552
|
+
}).catch(error => {
|
|
553
|
+
delete handlerRequests[key];
|
|
1090
554
|
/**
|
|
1091
|
-
*
|
|
555
|
+
* Let's cache the error!
|
|
1092
556
|
*/
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
if (_this2._mounted && _this2._propsMatch(propsAtFulfillment)) {
|
|
1097
|
-
_this2.setState({
|
|
1098
|
-
loading: false,
|
|
1099
|
-
data: null,
|
|
1100
|
-
error: typeof e === "string" ? e : e.message
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
return null;
|
|
557
|
+
|
|
558
|
+
return cacheError(handler, options, error);
|
|
1105
559
|
});
|
|
560
|
+
handlerRequests[key] = request;
|
|
561
|
+
return request;
|
|
562
|
+
} catch (e) {
|
|
563
|
+
/**
|
|
564
|
+
* In this case, we don't cache an inflight request, because there
|
|
565
|
+
* really isn't one.
|
|
566
|
+
*/
|
|
567
|
+
return Promise.resolve(cacheError(handler, options, e));
|
|
1106
568
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
this._responseCache = responseCache || _response_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* ResponseCache */ "a"].Default;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/***/ }),
|
|
577
|
+
/* 7 */
|
|
578
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
579
|
+
|
|
580
|
+
"use strict";
|
|
581
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return MemoryCache; });
|
|
582
|
+
function deepClone(source) {
|
|
583
|
+
/**
|
|
584
|
+
* We want to deep clone the source cache to dodge mutations by external
|
|
585
|
+
* references. So we serialize the source cache to JSON and parse it
|
|
586
|
+
* back into a new object.
|
|
587
|
+
*
|
|
588
|
+
* NOTE: This doesn't work for get/set property accessors.
|
|
589
|
+
*/
|
|
590
|
+
const serializedInitCache = JSON.stringify(source);
|
|
591
|
+
const cloneInitCache = JSON.parse(serializedInitCache);
|
|
592
|
+
return Object.freeze(cloneInitCache);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* INTERNAL USE ONLY
|
|
596
|
+
*
|
|
597
|
+
* Special case cache implementation for the memory cache.
|
|
598
|
+
*
|
|
599
|
+
* This is only used within our framework. Handlers don't need to
|
|
600
|
+
* provide this as a custom cache as the framework will default to this in the
|
|
601
|
+
* absence of a custom cache. We use this for SSR too (see ./response-cache.js).
|
|
602
|
+
*/
|
|
1115
603
|
|
|
1116
604
|
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
}
|
|
1123
|
-
}, {
|
|
1124
|
-
key: "_resultFromState",
|
|
1125
|
-
value: function _resultFromState() {
|
|
1126
|
-
var _this$state = this.state,
|
|
1127
|
-
loading = _this$state.loading,
|
|
1128
|
-
data = _this$state.data,
|
|
1129
|
-
error = _this$state.error;
|
|
1130
|
-
|
|
1131
|
-
if (loading) {
|
|
1132
|
-
return {
|
|
1133
|
-
loading: true
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
605
|
+
class MemoryCache {
|
|
606
|
+
constructor(source = null) {
|
|
607
|
+
this.store = (handler, options, entry) => {
|
|
608
|
+
const requestType = handler.type;
|
|
609
|
+
const frozenEntry = Object.isFrozen(entry) ? entry : Object.freeze(entry); // Ensure we have a cache location for this handler type.
|
|
1136
610
|
|
|
1137
|
-
|
|
1138
|
-
return {
|
|
1139
|
-
loading: false,
|
|
1140
|
-
data: data
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
611
|
+
this._cache[requestType] = this._cache[requestType] || {}; // Cache the data.
|
|
1143
612
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
}
|
|
613
|
+
const key = handler.getKey(options);
|
|
614
|
+
this._cache[requestType][key] = frozenEntry;
|
|
615
|
+
};
|
|
1148
616
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
error: error
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
}, {
|
|
1155
|
-
key: "_renderContent",
|
|
1156
|
-
value: function _renderContent(result) {
|
|
1157
|
-
var children = this.props.children;
|
|
1158
|
-
return children(result);
|
|
1159
|
-
}
|
|
1160
|
-
}, {
|
|
1161
|
-
key: "_renderWithTrackingContext",
|
|
1162
|
-
value: function _renderWithTrackingContext(result) {
|
|
1163
|
-
var _this3 = this;
|
|
617
|
+
this.retrieve = (handler, options) => {
|
|
618
|
+
const requestType = handler.type; // Get the internal subcache for the handler.
|
|
1164
619
|
|
|
1165
|
-
|
|
1166
|
-
/**
|
|
1167
|
-
* If data tracking wasn't enabled, don't do it.
|
|
1168
|
-
*/
|
|
1169
|
-
if (track != null) {
|
|
1170
|
-
track(_this3.props.handler, _this3.props.options);
|
|
1171
|
-
}
|
|
620
|
+
const handlerCache = this._cache[requestType];
|
|
1172
621
|
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
}, {
|
|
1177
|
-
key: "render",
|
|
1178
|
-
value: function render() {
|
|
1179
|
-
var result = this._resultFromState(); // We only track data requests when we are server-side and we don't
|
|
1180
|
-
// already have a result. The existence of a result is indicated by the
|
|
1181
|
-
// loading flag being false.
|
|
622
|
+
if (!handlerCache) {
|
|
623
|
+
return null;
|
|
624
|
+
} // Get the response.
|
|
1182
625
|
|
|
1183
626
|
|
|
1184
|
-
|
|
1185
|
-
|
|
627
|
+
const key = handler.getKey(options);
|
|
628
|
+
const internalEntry = handlerCache[key];
|
|
629
|
+
|
|
630
|
+
if (internalEntry == null) {
|
|
631
|
+
return null;
|
|
1186
632
|
}
|
|
1187
633
|
|
|
1188
|
-
return
|
|
1189
|
-
}
|
|
1190
|
-
|
|
634
|
+
return internalEntry;
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
this.remove = (handler, options) => {
|
|
638
|
+
const requestType = handler.type; // NOTE(somewhatabstract): We could invoke removeAll with a predicate
|
|
639
|
+
// to match the key of the entry we're removing, but that's an
|
|
640
|
+
// inefficient way to remove a single item, so let's not do that.
|
|
641
|
+
// Get the internal subcache for the handler.
|
|
1191
642
|
|
|
1192
|
-
|
|
1193
|
-
}(external_react_["Component"]);
|
|
643
|
+
const handlerCache = this._cache[requestType];
|
|
1194
644
|
|
|
645
|
+
if (!handlerCache) {
|
|
646
|
+
return false;
|
|
647
|
+
} // Get the entry.
|
|
1195
648
|
|
|
1196
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/components/intercept-context.js
|
|
1197
649
|
|
|
650
|
+
const key = handler.getKey(options);
|
|
651
|
+
const internalEntry = handlerCache[key];
|
|
1198
652
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
* INTERNAL USE ONLY
|
|
1203
|
-
*/
|
|
1204
|
-
var InterceptContext = external_react_["createContext"]({});
|
|
1205
|
-
/* harmony default export */ var intercept_context = (InterceptContext);
|
|
1206
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/components/data.js
|
|
1207
|
-
function data_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { data_typeof = function _typeof(obj) { return typeof obj; }; } else { data_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return data_typeof(obj); }
|
|
653
|
+
if (internalEntry == null) {
|
|
654
|
+
return false;
|
|
655
|
+
} // Delete the entry.
|
|
1208
656
|
|
|
1209
|
-
function data_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1210
657
|
|
|
1211
|
-
|
|
658
|
+
delete handlerCache[key];
|
|
659
|
+
return true;
|
|
660
|
+
};
|
|
1212
661
|
|
|
1213
|
-
|
|
662
|
+
this.removeAll = (handler, predicate) => {
|
|
663
|
+
const requestType = handler.type; // Get the internal subcache for the handler.
|
|
1214
664
|
|
|
1215
|
-
|
|
665
|
+
const handlerCache = this._cache[requestType];
|
|
1216
666
|
|
|
1217
|
-
|
|
667
|
+
if (!handlerCache) {
|
|
668
|
+
return 0;
|
|
669
|
+
} // Apply the predicate to what we have cached.
|
|
1218
670
|
|
|
1219
|
-
function data_createSuper(Derived) { var hasNativeReflectConstruct = data_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = data_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = data_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return data_possibleConstructorReturn(this, result); }; }
|
|
1220
671
|
|
|
1221
|
-
|
|
672
|
+
let removedCount = 0;
|
|
1222
673
|
|
|
1223
|
-
|
|
674
|
+
for (const [key, entry] of Object.entries(handlerCache)) {
|
|
675
|
+
if (typeof predicate !== "function" || predicate(key, entry)) {
|
|
676
|
+
removedCount++;
|
|
677
|
+
delete handlerCache[key];
|
|
678
|
+
}
|
|
679
|
+
}
|
|
1224
680
|
|
|
1225
|
-
|
|
681
|
+
return removedCount;
|
|
682
|
+
};
|
|
1226
683
|
|
|
1227
|
-
|
|
684
|
+
this.cloneData = () => {
|
|
685
|
+
try {
|
|
686
|
+
return deepClone(this._cache);
|
|
687
|
+
} catch (e) {
|
|
688
|
+
throw new Error(`An error occurred while trying to clone the cache: ${e}`);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
1228
691
|
|
|
692
|
+
this._cache = {};
|
|
1229
693
|
|
|
694
|
+
if (source != null) {
|
|
695
|
+
try {
|
|
696
|
+
/**
|
|
697
|
+
* Object.assign only performs a shallow clone.
|
|
698
|
+
* So we deep clone it and then assign the clone values to our
|
|
699
|
+
* internal cache.
|
|
700
|
+
*/
|
|
701
|
+
const cloneInitCache = deepClone(source);
|
|
702
|
+
Object.assign(this._cache, cloneInitCache);
|
|
703
|
+
} catch (e) {
|
|
704
|
+
throw new Error(`An error occurred trying to initialize from a response cache snapshot: ${e}`);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
1230
708
|
|
|
709
|
+
get inUse() {
|
|
710
|
+
return Object.keys(this._cache).length > 0;
|
|
711
|
+
}
|
|
1231
712
|
|
|
713
|
+
}
|
|
1232
714
|
|
|
715
|
+
/***/ }),
|
|
716
|
+
/* 8 */
|
|
717
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1233
718
|
|
|
719
|
+
"use strict";
|
|
720
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestHandler; });
|
|
1234
721
|
/**
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
722
|
+
* Base implementation for creating a request handler.
|
|
723
|
+
*
|
|
724
|
+
* Provides a base implementation of the `IRequestHandler` base class for
|
|
725
|
+
* use with the Wonder Blocks Data framework.
|
|
1238
726
|
*/
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
727
|
+
class RequestHandler {
|
|
728
|
+
constructor(type, cache, hydrate = true) {
|
|
729
|
+
this._type = type;
|
|
730
|
+
this._cache = cache || null;
|
|
731
|
+
this._hydrate = !!hydrate;
|
|
732
|
+
}
|
|
1243
733
|
|
|
1244
|
-
|
|
1245
|
-
|
|
734
|
+
get type() {
|
|
735
|
+
return this._type;
|
|
736
|
+
}
|
|
1246
737
|
|
|
1247
|
-
|
|
738
|
+
get cache() {
|
|
739
|
+
return this._cache;
|
|
1248
740
|
}
|
|
1249
741
|
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
var handler = this.props.handler;
|
|
742
|
+
get hydrate() {
|
|
743
|
+
return this._hydrate;
|
|
744
|
+
}
|
|
1254
745
|
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
746
|
+
shouldRefreshCache(options, cachedEntry) {
|
|
747
|
+
/**
|
|
748
|
+
* By default, the cache needs a refresh if the current entry is an
|
|
749
|
+
* error.
|
|
750
|
+
*
|
|
751
|
+
* This means that an error will cause a re-request on render.
|
|
752
|
+
* Useful if the server rendered an error, as it means the client
|
|
753
|
+
* will update after rehydration.
|
|
754
|
+
*/
|
|
755
|
+
return cachedEntry == null || cachedEntry.error != null;
|
|
756
|
+
}
|
|
1258
757
|
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
} : function (options) {
|
|
1265
|
-
return handler.fulfillRequest(options);
|
|
1266
|
-
};
|
|
1267
|
-
var shouldRefreshCacheFn = shouldRefreshCache ? function (options, cacheEntry) {
|
|
1268
|
-
var interceptedResult = shouldRefreshCache(options, cacheEntry);
|
|
1269
|
-
return interceptedResult != null ? interceptedResult : handler.shouldRefreshCache(options, cacheEntry);
|
|
1270
|
-
} : function (options, cacheEntry) {
|
|
1271
|
-
return handler.shouldRefreshCache(options, cacheEntry);
|
|
1272
|
-
};
|
|
1273
|
-
return {
|
|
1274
|
-
fulfillRequest: fulfillRequestFn,
|
|
1275
|
-
shouldRefreshCache: shouldRefreshCacheFn,
|
|
1276
|
-
getKey: function getKey(options) {
|
|
1277
|
-
return handler.getKey(options);
|
|
1278
|
-
},
|
|
1279
|
-
type: handler.type,
|
|
1280
|
-
cache: handler.cache,
|
|
1281
|
-
hydrate: handler.hydrate
|
|
1282
|
-
};
|
|
758
|
+
getKey(options) {
|
|
759
|
+
try {
|
|
760
|
+
return options === undefined ? "undefined" : JSON.stringify(options);
|
|
761
|
+
} catch (e) {
|
|
762
|
+
throw new Error(`Failed to auto-generate key: ${e}`);
|
|
1283
763
|
}
|
|
1284
|
-
}
|
|
1285
|
-
key: "_getCacheLookupFnFromInterceptor",
|
|
1286
|
-
value: function _getCacheLookupFnFromInterceptor(interceptor) {
|
|
1287
|
-
var getEntry = interceptor && interceptor.getEntry;
|
|
764
|
+
}
|
|
1288
765
|
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
766
|
+
fulfillRequest(options) {
|
|
767
|
+
throw new Error("Not implemented");
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/***/ }),
|
|
773
|
+
/* 9 */
|
|
774
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1292
775
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
776
|
+
"use strict";
|
|
777
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return TrackData; });
|
|
778
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
779
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
780
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
|
|
781
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
|
|
782
|
+
/* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
|
|
1296
783
|
|
|
1297
|
-
var interceptedData = getEntry(options, cacheEntry); // 3. Return the appropriate response.
|
|
1298
784
|
|
|
1299
|
-
|
|
1300
|
-
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Component to enable data request tracking when server-side rendering.
|
|
789
|
+
*/
|
|
790
|
+
class TrackData extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
791
|
+
render() {
|
|
792
|
+
if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["Server"].isServerSide()) {
|
|
793
|
+
throw new Error("This component is not for use during client-side rendering");
|
|
1301
794
|
}
|
|
1302
|
-
}, {
|
|
1303
|
-
key: "render",
|
|
1304
|
-
value: function render() {
|
|
1305
|
-
var _this = this;
|
|
1306
795
|
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
796
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* TrackerContext */ "b"].Provider, {
|
|
797
|
+
value: _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestTracker */ "a"].Default.trackDataRequest
|
|
798
|
+
}, this.props.children);
|
|
799
|
+
}
|
|
1310
800
|
|
|
1311
|
-
|
|
801
|
+
}
|
|
1312
802
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
803
|
+
/***/ }),
|
|
804
|
+
/* 10 */
|
|
805
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
806
|
+
|
|
807
|
+
"use strict";
|
|
808
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Data; });
|
|
809
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
810
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
811
|
+
/* harmony import */ var _util_response_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
|
|
812
|
+
/* harmony import */ var _internal_data_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13);
|
|
813
|
+
/* harmony import */ var _intercept_context_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
|
|
1322
814
|
|
|
1323
815
|
|
|
1324
|
-
return /*#__PURE__*/external_react_["createElement"](internal_data_InternalData // $FlowIgnore[incompatible-type-arg]
|
|
1325
|
-
, {
|
|
1326
|
-
handler: handler,
|
|
1327
|
-
options: _this.props.options,
|
|
1328
|
-
getEntry: getEntry
|
|
1329
|
-
}, function (result) {
|
|
1330
|
-
return _this.props.children(result);
|
|
1331
|
-
});
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
}]);
|
|
1335
816
|
|
|
1336
|
-
return Data;
|
|
1337
|
-
}(external_react_["Component"]);
|
|
1338
817
|
|
|
1339
818
|
|
|
1340
|
-
|
|
1341
|
-
|
|
819
|
+
/**
|
|
820
|
+
* This component is the main component of Wonder Blocks Data. With this, data
|
|
821
|
+
* requirements can be placed in a React application in a manner that will
|
|
822
|
+
* support server-side rendering and efficient caching.
|
|
823
|
+
*/
|
|
824
|
+
class Data extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
825
|
+
_getHandlerFromInterceptor(interceptor) {
|
|
826
|
+
const {
|
|
827
|
+
handler
|
|
828
|
+
} = this.props;
|
|
829
|
+
|
|
830
|
+
if (!interceptor) {
|
|
831
|
+
return handler;
|
|
832
|
+
}
|
|
1342
833
|
|
|
1343
|
-
|
|
834
|
+
const {
|
|
835
|
+
fulfillRequest,
|
|
836
|
+
shouldRefreshCache
|
|
837
|
+
} = interceptor;
|
|
838
|
+
const fulfillRequestFn = fulfillRequest ? options => {
|
|
839
|
+
const interceptedResult = fulfillRequest(options);
|
|
840
|
+
return interceptedResult != null ? interceptedResult : handler.fulfillRequest(options);
|
|
841
|
+
} : options => handler.fulfillRequest(options);
|
|
842
|
+
const shouldRefreshCacheFn = shouldRefreshCache ? (options, cacheEntry) => {
|
|
843
|
+
const interceptedResult = shouldRefreshCache(options, cacheEntry);
|
|
844
|
+
return interceptedResult != null ? interceptedResult : handler.shouldRefreshCache(options, cacheEntry);
|
|
845
|
+
} : (options, cacheEntry) => handler.shouldRefreshCache(options, cacheEntry);
|
|
846
|
+
return {
|
|
847
|
+
fulfillRequest: fulfillRequestFn,
|
|
848
|
+
shouldRefreshCache: shouldRefreshCacheFn,
|
|
849
|
+
getKey: options => handler.getKey(options),
|
|
850
|
+
type: handler.type,
|
|
851
|
+
cache: handler.cache,
|
|
852
|
+
hydrate: handler.hydrate
|
|
853
|
+
};
|
|
854
|
+
}
|
|
1344
855
|
|
|
1345
|
-
|
|
856
|
+
_getCacheLookupFnFromInterceptor(interceptor) {
|
|
857
|
+
const getEntry = interceptor && interceptor.getEntry;
|
|
1346
858
|
|
|
1347
|
-
|
|
859
|
+
if (!getEntry) {
|
|
860
|
+
return _util_response_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseCache */ "a"].Default.getEntry;
|
|
861
|
+
}
|
|
1348
862
|
|
|
1349
|
-
|
|
863
|
+
return (handler, options) => {
|
|
864
|
+
// 1. Lookup the current cache value.
|
|
865
|
+
const cacheEntry = _util_response_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseCache */ "a"].Default.getEntry(handler, options); // 2. See if our interceptor wants to override it.
|
|
1350
866
|
|
|
1351
|
-
|
|
867
|
+
const interceptedData = getEntry(options, cacheEntry); // 3. Return the appropriate response.
|
|
1352
868
|
|
|
1353
|
-
|
|
869
|
+
return interceptedData != null ? interceptedData : cacheEntry;
|
|
870
|
+
};
|
|
871
|
+
}
|
|
1354
872
|
|
|
1355
|
-
|
|
873
|
+
render() {
|
|
874
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_intercept_context_js__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"].Consumer, null, value => {
|
|
875
|
+
const handlerType = this.props.handler.type;
|
|
876
|
+
const interceptor = value[handlerType];
|
|
1356
877
|
|
|
1357
|
-
|
|
878
|
+
const handler = this._getHandlerFromInterceptor(interceptor);
|
|
1358
879
|
|
|
1359
|
-
|
|
880
|
+
const getEntry = this._getCacheLookupFnFromInterceptor(interceptor);
|
|
881
|
+
/**
|
|
882
|
+
* Need to share our types with InternalData so Flow
|
|
883
|
+
* doesn't need to infer them and find mismatches.
|
|
884
|
+
* However, just deriving a new component creates issues
|
|
885
|
+
* where InternalData starts rerendering too often.
|
|
886
|
+
* Couldn't track down why, so suppressing the error
|
|
887
|
+
* instead.
|
|
888
|
+
*/
|
|
1360
889
|
|
|
1361
|
-
function intercept_data_possibleConstructorReturn(self, call) { if (call && (intercept_data_typeof(call) === "object" || typeof call === "function")) { return call; } return intercept_data_assertThisInitialized(self); }
|
|
1362
890
|
|
|
1363
|
-
|
|
891
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_internal_data_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"] // $FlowIgnore[incompatible-type-arg]
|
|
892
|
+
, {
|
|
893
|
+
handler: handler,
|
|
894
|
+
options: this.props.options,
|
|
895
|
+
getEntry: getEntry
|
|
896
|
+
}, result => this.props.children(result));
|
|
897
|
+
});
|
|
898
|
+
}
|
|
1364
899
|
|
|
1365
|
-
|
|
900
|
+
}
|
|
1366
901
|
|
|
1367
|
-
|
|
902
|
+
/***/ }),
|
|
903
|
+
/* 11 */
|
|
904
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1368
905
|
|
|
906
|
+
"use strict";
|
|
907
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return InterceptData; });
|
|
908
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
909
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
910
|
+
/* harmony import */ var _intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
|
|
1369
911
|
|
|
1370
912
|
|
|
1371
913
|
|
|
@@ -1388,153 +930,323 @@ function intercept_data_getPrototypeOf(o) { intercept_data_getPrototypeOf = Obje
|
|
|
1388
930
|
* new instance will replace this interceptor for its children. All methods
|
|
1389
931
|
* will be replaced.
|
|
1390
932
|
*/
|
|
1391
|
-
|
|
1392
|
-
|
|
933
|
+
class InterceptData extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
934
|
+
render() {
|
|
935
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].Consumer, null, value => {
|
|
936
|
+
const handlerType = this.props.handler.type;
|
|
937
|
+
const interceptor = { ...value[handlerType],
|
|
938
|
+
fulfillRequest: this.props.fulfillRequest || null,
|
|
939
|
+
shouldRefreshCache: this.props.shouldRefreshCache || null
|
|
940
|
+
};
|
|
941
|
+
const newValue = { ...value,
|
|
942
|
+
[handlerType]: interceptor
|
|
943
|
+
};
|
|
944
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].Provider, {
|
|
945
|
+
value: newValue
|
|
946
|
+
}, this.props.children);
|
|
947
|
+
});
|
|
948
|
+
}
|
|
1393
949
|
|
|
1394
|
-
|
|
950
|
+
}
|
|
1395
951
|
|
|
1396
|
-
|
|
1397
|
-
|
|
952
|
+
/***/ }),
|
|
953
|
+
/* 12 */
|
|
954
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1398
955
|
|
|
1399
|
-
|
|
1400
|
-
|
|
956
|
+
"use strict";
|
|
957
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return InterceptCache; });
|
|
958
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
959
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
960
|
+
/* harmony import */ var _intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
|
|
1401
961
|
|
|
1402
|
-
intercept_data_createClass(InterceptData, [{
|
|
1403
|
-
key: "render",
|
|
1404
|
-
value: function render() {
|
|
1405
|
-
var _this = this;
|
|
1406
962
|
|
|
1407
|
-
return /*#__PURE__*/external_react_["createElement"](intercept_context.Consumer, null, function (value) {
|
|
1408
|
-
var handlerType = _this.props.handler.type;
|
|
1409
963
|
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
964
|
+
/**
|
|
965
|
+
* This component provides a mechanism to intercept cache lookups for the
|
|
966
|
+
* type of a given handler and provide alternative values. This is mostly
|
|
967
|
+
* useful for testing.
|
|
968
|
+
*
|
|
969
|
+
* This does not modify the cache in any way. If you want to intercept
|
|
970
|
+
* requests and cache based on the intercept, then use `InterceptData`.
|
|
971
|
+
*
|
|
972
|
+
* This component is generally not suitable for use in production code as it
|
|
973
|
+
* can prevent predictable functioning of the Wonder Blocks Data framework.
|
|
974
|
+
*
|
|
975
|
+
* These components do not chain. If a different `InterceptCache` instance is
|
|
976
|
+
* rendered within this one that intercepts the same handler type, then that
|
|
977
|
+
* new instance will replace this interceptor for its children.
|
|
978
|
+
*/
|
|
979
|
+
class InterceptCache extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
980
|
+
render() {
|
|
981
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].Consumer, null, value => {
|
|
982
|
+
const handlerType = this.props.handler.type;
|
|
983
|
+
const interceptor = { ...value[handlerType],
|
|
984
|
+
getEntry: this.props.getEntry
|
|
985
|
+
};
|
|
986
|
+
const newValue = { ...value,
|
|
987
|
+
[handlerType]: interceptor
|
|
988
|
+
};
|
|
989
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].Provider, {
|
|
990
|
+
value: newValue
|
|
991
|
+
}, this.props.children);
|
|
992
|
+
});
|
|
993
|
+
}
|
|
1414
994
|
|
|
1415
|
-
|
|
995
|
+
}
|
|
1416
996
|
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
997
|
+
/***/ }),
|
|
998
|
+
/* 13 */
|
|
999
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1000
|
+
|
|
1001
|
+
"use strict";
|
|
1002
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return InternalData; });
|
|
1003
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
1004
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
1005
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
|
|
1006
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
|
|
1007
|
+
/* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
|
|
1008
|
+
/* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3);
|
|
1423
1009
|
|
|
1424
|
-
return InterceptData;
|
|
1425
|
-
}(external_react_["Component"]);
|
|
1426
1010
|
|
|
1427
1011
|
|
|
1428
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-data/src/components/intercept-cache.js
|
|
1429
|
-
function intercept_cache_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { intercept_cache_typeof = function _typeof(obj) { return typeof obj; }; } else { intercept_cache_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return intercept_cache_typeof(obj); }
|
|
1430
1012
|
|
|
1431
|
-
function intercept_cache_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
1432
1013
|
|
|
1433
|
-
|
|
1014
|
+
/**
|
|
1015
|
+
* This component is responsible for actually handling the data request.
|
|
1016
|
+
* It is wrapped by Data in order to support intercepts and be exported for use.
|
|
1017
|
+
*
|
|
1018
|
+
* INTERNAL USE ONLY
|
|
1019
|
+
*/
|
|
1020
|
+
class InternalData extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
1021
|
+
constructor(props) {
|
|
1022
|
+
super(props);
|
|
1023
|
+
this.state = this._buildStateAndfulfillNeeds(props);
|
|
1024
|
+
}
|
|
1434
1025
|
|
|
1435
|
-
|
|
1026
|
+
componentDidMount() {
|
|
1027
|
+
this._mounted = true;
|
|
1028
|
+
}
|
|
1436
1029
|
|
|
1437
|
-
|
|
1030
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
1031
|
+
/**
|
|
1032
|
+
* We only bother updating if our state changed.
|
|
1033
|
+
*
|
|
1034
|
+
* And we only update the state if props changed
|
|
1035
|
+
* or we got new data/error.
|
|
1036
|
+
*/
|
|
1037
|
+
if (!this._propsMatch(nextProps)) {
|
|
1038
|
+
const newState = this._buildStateAndfulfillNeeds(nextProps);
|
|
1438
1039
|
|
|
1439
|
-
|
|
1040
|
+
this.setState(newState);
|
|
1041
|
+
}
|
|
1440
1042
|
|
|
1441
|
-
|
|
1043
|
+
return this.state.loading !== nextState.loading || this.state.data !== nextState.data || this.state.error !== nextState.error;
|
|
1044
|
+
}
|
|
1442
1045
|
|
|
1443
|
-
|
|
1046
|
+
componentWillUnmount() {
|
|
1047
|
+
this._mounted = false;
|
|
1048
|
+
}
|
|
1444
1049
|
|
|
1445
|
-
|
|
1050
|
+
_propsMatch(otherProps) {
|
|
1051
|
+
const {
|
|
1052
|
+
handler,
|
|
1053
|
+
options
|
|
1054
|
+
} = this.props;
|
|
1055
|
+
const {
|
|
1056
|
+
handler: prevHandler,
|
|
1057
|
+
options: prevOptions
|
|
1058
|
+
} = otherProps;
|
|
1059
|
+
return handler === prevHandler && handler.getKey(options) === prevHandler.getKey(prevOptions);
|
|
1060
|
+
}
|
|
1446
1061
|
|
|
1447
|
-
|
|
1062
|
+
_buildStateAndfulfillNeeds(propsAtFulfillment) {
|
|
1063
|
+
const {
|
|
1064
|
+
getEntry,
|
|
1065
|
+
handler,
|
|
1066
|
+
options
|
|
1067
|
+
} = propsAtFulfillment;
|
|
1068
|
+
const cachedData = getEntry(handler, options);
|
|
1448
1069
|
|
|
1449
|
-
|
|
1070
|
+
if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["Server"].isServerSide() && (cachedData == null || handler.shouldRefreshCache(options, cachedData))) {
|
|
1071
|
+
/**
|
|
1072
|
+
* We're not on the server, the cache missed, or our handler says
|
|
1073
|
+
* we should refresh the cache.
|
|
1074
|
+
*
|
|
1075
|
+
* Therefore, we need to request data.
|
|
1076
|
+
*
|
|
1077
|
+
* We have to do this here from the constructor so that this
|
|
1078
|
+
* data request is tracked when performing server-side rendering.
|
|
1079
|
+
*/
|
|
1080
|
+
_util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestFulfillment */ "a"].Default.fulfill(handler, options).then(cacheEntry => {
|
|
1081
|
+
/**
|
|
1082
|
+
* We get here, we should have updated the cache.
|
|
1083
|
+
* However, we need to update the component, but we
|
|
1084
|
+
* should only do that if the props are the same as they
|
|
1085
|
+
* were when this was called.
|
|
1086
|
+
*/
|
|
1087
|
+
if (this._mounted && this._propsMatch(propsAtFulfillment)) {
|
|
1088
|
+
this.setState({
|
|
1089
|
+
loading: false,
|
|
1090
|
+
data: cacheEntry.data,
|
|
1091
|
+
error: cacheEntry.error
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1450
1094
|
|
|
1451
|
-
|
|
1095
|
+
return null;
|
|
1096
|
+
}).catch(e => {
|
|
1097
|
+
/**
|
|
1098
|
+
* We should never get here, but if we do.
|
|
1099
|
+
*/
|
|
1100
|
+
// eslint-disable-next-line no-console
|
|
1101
|
+
console.error(`Unexpected error occurred during data fulfillment: ${e}`);
|
|
1102
|
+
|
|
1103
|
+
if (this._mounted && this._propsMatch(propsAtFulfillment)) {
|
|
1104
|
+
this.setState({
|
|
1105
|
+
loading: false,
|
|
1106
|
+
data: null,
|
|
1107
|
+
error: typeof e === "string" ? e : e.message
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1452
1110
|
|
|
1453
|
-
|
|
1111
|
+
return null;
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* This is the default response for the server and for the initial
|
|
1116
|
+
* client-side render if we have cachedData.
|
|
1117
|
+
*
|
|
1118
|
+
* This ensures we don't make promises we don't want when doing
|
|
1119
|
+
* server-side rendering. Instead, we either have data from the cache
|
|
1120
|
+
* or we don't.
|
|
1121
|
+
*/
|
|
1454
1122
|
|
|
1455
|
-
function intercept_cache_getPrototypeOf(o) { intercept_cache_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return intercept_cache_getPrototypeOf(o); }
|
|
1456
1123
|
|
|
1124
|
+
return {
|
|
1125
|
+
loading: cachedData == null,
|
|
1126
|
+
data: cachedData && cachedData.data,
|
|
1127
|
+
error: cachedData && cachedData.error
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1457
1130
|
|
|
1131
|
+
_resultFromState() {
|
|
1132
|
+
const {
|
|
1133
|
+
loading,
|
|
1134
|
+
data,
|
|
1135
|
+
error
|
|
1136
|
+
} = this.state;
|
|
1458
1137
|
|
|
1138
|
+
if (loading) {
|
|
1139
|
+
return {
|
|
1140
|
+
loading: true
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1459
1143
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
* requests and cache based on the intercept, then use `InterceptData`.
|
|
1467
|
-
*
|
|
1468
|
-
* This component is generally not suitable for use in production code as it
|
|
1469
|
-
* can prevent predictable functioning of the Wonder Blocks Data framework.
|
|
1470
|
-
*
|
|
1471
|
-
* These components do not chain. If a different `InterceptCache` instance is
|
|
1472
|
-
* rendered within this one that intercepts the same handler type, then that
|
|
1473
|
-
* new instance will replace this interceptor for its children.
|
|
1474
|
-
*/
|
|
1475
|
-
var intercept_cache_InterceptCache = /*#__PURE__*/function (_React$Component) {
|
|
1476
|
-
intercept_cache_inherits(InterceptCache, _React$Component);
|
|
1144
|
+
if (data != null) {
|
|
1145
|
+
return {
|
|
1146
|
+
loading: false,
|
|
1147
|
+
data
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1477
1150
|
|
|
1478
|
-
|
|
1151
|
+
if (error == null) {
|
|
1152
|
+
// We should never get here ever.
|
|
1153
|
+
throw new Error("Loaded result has invalid state where data and error are missing");
|
|
1154
|
+
}
|
|
1479
1155
|
|
|
1480
|
-
|
|
1481
|
-
|
|
1156
|
+
return {
|
|
1157
|
+
loading: false,
|
|
1158
|
+
error
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1482
1161
|
|
|
1483
|
-
|
|
1162
|
+
_renderContent(result) {
|
|
1163
|
+
const {
|
|
1164
|
+
children
|
|
1165
|
+
} = this.props;
|
|
1166
|
+
return children(result);
|
|
1484
1167
|
}
|
|
1485
1168
|
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1169
|
+
_renderWithTrackingContext(result) {
|
|
1170
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_util_request_tracking_js__WEBPACK_IMPORTED_MODULE_3__[/* TrackerContext */ "b"].Consumer, null, track => {
|
|
1171
|
+
/**
|
|
1172
|
+
* If data tracking wasn't enabled, don't do it.
|
|
1173
|
+
*/
|
|
1174
|
+
if (track != null) {
|
|
1175
|
+
track(this.props.handler, this.props.options);
|
|
1176
|
+
}
|
|
1490
1177
|
|
|
1491
|
-
return
|
|
1492
|
-
|
|
1178
|
+
return this._renderContent(result);
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1493
1181
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1182
|
+
render() {
|
|
1183
|
+
const result = this._resultFromState(); // We only track data requests when we are server-side and we don't
|
|
1184
|
+
// already have a result. The existence of a result is indicated by the
|
|
1185
|
+
// loading flag being false.
|
|
1497
1186
|
|
|
1498
|
-
var newValue = intercept_cache_objectSpread(intercept_cache_objectSpread({}, value), {}, intercept_cache_defineProperty({}, handlerType, interceptor));
|
|
1499
1187
|
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
}, _this.props.children);
|
|
1503
|
-
});
|
|
1188
|
+
if (result.loading && _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["Server"].isServerSide()) {
|
|
1189
|
+
return this._renderWithTrackingContext(result);
|
|
1504
1190
|
}
|
|
1505
|
-
}]);
|
|
1506
1191
|
|
|
1507
|
-
|
|
1508
|
-
}
|
|
1192
|
+
return this._renderContent(result);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
}
|
|
1509
1196
|
|
|
1197
|
+
/***/ }),
|
|
1198
|
+
/* 14 */
|
|
1199
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1510
1200
|
|
|
1511
|
-
|
|
1201
|
+
"use strict";
|
|
1202
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1203
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "initializeCache", function() { return initializeCache; });
|
|
1204
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fulfillAllDataRequests", function() { return fulfillAllDataRequests; });
|
|
1205
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasUnfulfilledRequests", function() { return hasUnfulfilledRequests; });
|
|
1206
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeFromCache", function() { return removeFromCache; });
|
|
1207
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeAllFromCache", function() { return removeAllFromCache; });
|
|
1208
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
|
1209
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
|
|
1210
|
+
/* harmony import */ var _util_response_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
|
|
1211
|
+
/* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
|
|
1212
|
+
/* harmony import */ var _util_request_handler_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8);
|
|
1213
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RequestHandler", function() { return _util_request_handler_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
|
|
1512
1214
|
|
|
1215
|
+
/* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9);
|
|
1216
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TrackData", function() { return _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
|
|
1513
1217
|
|
|
1218
|
+
/* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(10);
|
|
1219
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Data", function() { return _components_data_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
|
|
1514
1220
|
|
|
1515
|
-
var
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
var
|
|
1519
|
-
|
|
1221
|
+
/* harmony import */ var _components_intercept_data_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(11);
|
|
1222
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "InterceptData", function() { return _components_intercept_data_js__WEBPACK_IMPORTED_MODULE_6__["a"]; });
|
|
1223
|
+
|
|
1224
|
+
/* harmony import */ var _components_intercept_cache_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(12);
|
|
1225
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "InterceptCache", function() { return _components_intercept_cache_js__WEBPACK_IMPORTED_MODULE_7__["a"]; });
|
|
1226
|
+
|
|
1227
|
+
/* harmony import */ var _util_no_cache_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(5);
|
|
1228
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "NoCache", function() { return _util_no_cache_js__WEBPACK_IMPORTED_MODULE_8__["a"]; });
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
const initializeCache = source => _util_response_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseCache */ "a"].Default.initialize(source);
|
|
1234
|
+
const fulfillAllDataRequests = () => {
|
|
1235
|
+
if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
|
|
1520
1236
|
return Promise.reject(new Error("Data requests are not tracked when client-side"));
|
|
1521
1237
|
}
|
|
1522
1238
|
|
|
1523
|
-
return
|
|
1239
|
+
return _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestTracker */ "a"].Default.fulfillTrackedRequests();
|
|
1524
1240
|
};
|
|
1525
|
-
|
|
1526
|
-
if (!
|
|
1241
|
+
const hasUnfulfilledRequests = () => {
|
|
1242
|
+
if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
|
|
1527
1243
|
throw new Error("Data requests are not tracked when client-side");
|
|
1528
1244
|
}
|
|
1529
1245
|
|
|
1530
|
-
return
|
|
1531
|
-
};
|
|
1532
|
-
var src_removeFromCache = function removeFromCache(handler, options) {
|
|
1533
|
-
return response_cache_ResponseCache.Default.remove(handler, options);
|
|
1534
|
-
};
|
|
1535
|
-
var src_removeAllFromCache = function removeAllFromCache(handler, predicate) {
|
|
1536
|
-
return response_cache_ResponseCache.Default.removeAll(handler, predicate);
|
|
1246
|
+
return _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestTracker */ "a"].Default.hasUnfulfilledRequests;
|
|
1537
1247
|
};
|
|
1248
|
+
const removeFromCache = (handler, options) => _util_response_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseCache */ "a"].Default.remove(handler, options);
|
|
1249
|
+
const removeAllFromCache = (handler, predicate) => _util_response_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseCache */ "a"].Default.removeAll(handler, predicate);
|
|
1538
1250
|
/**
|
|
1539
1251
|
* TODO(somewhatabstract): Export each cache type we implement.
|
|
1540
1252
|
*
|