@mjhls/mjh-framework 1.0.850-beta.0 → 1.0.850-beta.1

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.
Files changed (55) hide show
  1. package/dist/cjs/AdSlotsProvider.js +2 -895
  2. package/dist/cjs/AlgoliaSearch.js +336 -237
  3. package/dist/cjs/ArticleProgramLandingPage.js +2 -3
  4. package/dist/cjs/ArticleSeriesLandingPage.js +1 -1
  5. package/dist/cjs/ArticleSeriesListing.js +1 -1
  6. package/dist/cjs/DeckContent.js +1 -1
  7. package/dist/cjs/DeckQueue.js +1 -1
  8. package/dist/cjs/ExternalResources.js +2 -3
  9. package/dist/cjs/GridContent.js +1 -1
  10. package/dist/cjs/HorizontalArticleListing.js +2 -3
  11. package/dist/cjs/IssueLanding.js +2 -3
  12. package/dist/cjs/MasterDeck.js +1 -1
  13. package/dist/cjs/MediaSeriesLanding.js +5 -6
  14. package/dist/cjs/PartnerDetailListing.js +6 -1105
  15. package/dist/cjs/QueueDeckExpanded.js +1098 -112
  16. package/dist/cjs/TaxonomyDescription.js +2 -3
  17. package/dist/cjs/VideoProgramLandingPage.js +2 -3
  18. package/dist/cjs/VideoSeriesCard.js +2 -2
  19. package/dist/cjs/VideoSeriesLandingPage.js +3 -3
  20. package/dist/cjs/VideoSeriesListing.js +1 -1
  21. package/dist/cjs/View.js +5 -7
  22. package/dist/cjs/faundadb.js +321 -4
  23. package/dist/cjs/getRelatedArticle.js +21 -438
  24. package/dist/cjs/getSerializers.js +2 -3
  25. package/dist/cjs/{index-bc88f898.js → index-4151deb3.js} +587 -15
  26. package/dist/cjs/index.js +6 -13
  27. package/dist/cjs/{inherits-452ff02c.js → inherits-9953db94.js} +4 -4
  28. package/dist/esm/AdSlotsProvider.js +6 -898
  29. package/dist/esm/AlgoliaSearch.js +100 -1
  30. package/dist/esm/ArticleProgramLandingPage.js +1 -2
  31. package/dist/esm/ExternalResources.js +1 -2
  32. package/dist/esm/HorizontalArticleListing.js +1 -2
  33. package/dist/esm/IssueLanding.js +1 -2
  34. package/dist/esm/MediaSeriesLanding.js +1 -2
  35. package/dist/esm/PartnerDetailListing.js +5 -1103
  36. package/dist/esm/QueueDeckExpanded.js +1099 -113
  37. package/dist/esm/TaxonomyDescription.js +1 -2
  38. package/dist/esm/VideoProgramLandingPage.js +1 -2
  39. package/dist/esm/View.js +2 -4
  40. package/dist/esm/faundadb.js +319 -2
  41. package/dist/esm/getRelatedArticle.js +21 -438
  42. package/dist/esm/getSerializers.js +1 -2
  43. package/dist/esm/{index-f2a0d400.js → index-d6dc592a.js} +575 -3
  44. package/dist/esm/index.js +4 -10
  45. package/package.json +8 -3
  46. package/dist/cjs/Auth.js +0 -3428
  47. package/dist/cjs/index-bd6c9f56.js +0 -211
  48. package/dist/cjs/inherits-8d29278d.js +0 -110
  49. package/dist/cjs/md5-5039b1a6.js +0 -323
  50. package/dist/cjs/util-f2c1b65b.js +0 -576
  51. package/dist/esm/Auth.js +0 -3412
  52. package/dist/esm/index-db3bb315.js +0 -207
  53. package/dist/esm/inherits-77d5e4fc.js +0 -101
  54. package/dist/esm/md5-9be0e905.js +0 -321
  55. package/dist/esm/util-7700fc59.js +0 -574
@@ -8,7 +8,7 @@ import './core.get-iterator-method-e1de7503.js';
8
8
  import './_object-pie-33c40e79.js';
9
9
  import { _ as _extends } from './extends-6f2fcc99.js';
10
10
  import './web.dom.iterable-4439f05a.js';
11
- import React__default, { useEffect, useState, useRef } from 'react';
11
+ import React__default, { useEffect, useLayoutEffect, createContext, useContext, useRef, useDebugValue, useState, useCallback, useMemo } from 'react';
12
12
  import './events-6c3a7a63.js';
13
13
  import { l as lib_3 } from './index-41a678ea.js';
14
14
  import 'prop-types';
@@ -46,6 +46,1055 @@ var reactPaginate = createCommonjsModule(function (module, exports) {
46
46
  var ReactPaginate = unwrapExports(reactPaginate);
47
47
  var reactPaginate_1 = reactPaginate.ReactPaginate;
48
48
 
49
+ var has = Object.prototype.hasOwnProperty;
50
+
51
+ function dequal(foo, bar) {
52
+ var ctor, len;
53
+ if (foo === bar) return true;
54
+
55
+ if (foo && bar && (ctor=foo.constructor) === bar.constructor) {
56
+ if (ctor === Date) return foo.getTime() === bar.getTime();
57
+ if (ctor === RegExp) return foo.toString() === bar.toString();
58
+
59
+ if (ctor === Array) {
60
+ if ((len=foo.length) === bar.length) {
61
+ while (len-- && dequal(foo[len], bar[len]));
62
+ }
63
+ return len === -1;
64
+ }
65
+
66
+ if (!ctor || typeof foo === 'object') {
67
+ len = 0;
68
+ for (ctor in foo) {
69
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
70
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
71
+ }
72
+ return Object.keys(bar).length === len;
73
+ }
74
+ }
75
+
76
+ return foo !== foo && bar !== bar;
77
+ }
78
+
79
+ // use WeakMap to store the object->key mapping
80
+ // so the objects can be garbage collected.
81
+ // WeakMap uses a hashtable under the hood, so the lookup
82
+ // complexity is almost O(1).
83
+ var table = new WeakMap();
84
+ // counter of the key
85
+ var counter = 0;
86
+ // hashes an array of objects and returns a string
87
+ function hash(args) {
88
+ if (!args.length)
89
+ return '';
90
+ var key = 'arg';
91
+ for (var i = 0; i < args.length; ++i) {
92
+ if (args[i] === null) {
93
+ key += '@null';
94
+ continue;
95
+ }
96
+ var _hash = void 0;
97
+ if (typeof args[i] !== 'object' && typeof args[i] !== 'function') {
98
+ // need to consider the case that args[i] is a string:
99
+ // args[i] _hash
100
+ // "undefined" -> '"undefined"'
101
+ // undefined -> 'undefined'
102
+ // 123 -> '123'
103
+ // "null" -> '"null"'
104
+ if (typeof args[i] === 'string') {
105
+ _hash = '"' + args[i] + '"';
106
+ }
107
+ else {
108
+ _hash = String(args[i]);
109
+ }
110
+ }
111
+ else {
112
+ if (!table.has(args[i])) {
113
+ _hash = counter;
114
+ table.set(args[i], counter++);
115
+ }
116
+ else {
117
+ _hash = table.get(args[i]);
118
+ }
119
+ }
120
+ key += '@' + _hash;
121
+ }
122
+ return key;
123
+ }
124
+
125
+ var Cache = /** @class */ (function () {
126
+ function Cache(initialData) {
127
+ if (initialData === void 0) { initialData = {}; }
128
+ this.cache = new Map(Object.entries(initialData));
129
+ this.subs = [];
130
+ }
131
+ Cache.prototype.get = function (key) {
132
+ var _key = this.serializeKey(key)[0];
133
+ return this.cache.get(_key);
134
+ };
135
+ Cache.prototype.set = function (key, value) {
136
+ var _key = this.serializeKey(key)[0];
137
+ this.cache.set(_key, value);
138
+ this.notify();
139
+ };
140
+ Cache.prototype.keys = function () {
141
+ return Array.from(this.cache.keys());
142
+ };
143
+ Cache.prototype.has = function (key) {
144
+ var _key = this.serializeKey(key)[0];
145
+ return this.cache.has(_key);
146
+ };
147
+ Cache.prototype.clear = function () {
148
+ this.cache.clear();
149
+ this.notify();
150
+ };
151
+ Cache.prototype.delete = function (key) {
152
+ var _key = this.serializeKey(key)[0];
153
+ this.cache.delete(_key);
154
+ this.notify();
155
+ };
156
+ // TODO: introduce namespace for the cache
157
+ Cache.prototype.serializeKey = function (key) {
158
+ var args = null;
159
+ if (typeof key === 'function') {
160
+ try {
161
+ key = key();
162
+ }
163
+ catch (err) {
164
+ // dependencies not ready
165
+ key = '';
166
+ }
167
+ }
168
+ if (Array.isArray(key)) {
169
+ // args array
170
+ args = key;
171
+ key = hash(key);
172
+ }
173
+ else {
174
+ // convert null to ''
175
+ key = String(key || '');
176
+ }
177
+ var errorKey = key ? 'err@' + key : '';
178
+ var isValidatingKey = key ? 'validating@' + key : '';
179
+ return [key, args, errorKey, isValidatingKey];
180
+ };
181
+ Cache.prototype.subscribe = function (listener) {
182
+ var _this = this;
183
+ if (typeof listener !== 'function') {
184
+ throw new Error('Expected the listener to be a function.');
185
+ }
186
+ var isSubscribed = true;
187
+ this.subs.push(listener);
188
+ return function () {
189
+ if (!isSubscribed)
190
+ return;
191
+ isSubscribed = false;
192
+ var index = _this.subs.indexOf(listener);
193
+ if (index > -1) {
194
+ _this.subs[index] = _this.subs[_this.subs.length - 1];
195
+ _this.subs.length--;
196
+ }
197
+ };
198
+ };
199
+ // Notify Cache subscribers about a change in the cache
200
+ Cache.prototype.notify = function () {
201
+ for (var _i = 0, _a = this.subs; _i < _a.length; _i++) {
202
+ var listener = _a[_i];
203
+ listener();
204
+ }
205
+ };
206
+ return Cache;
207
+ }());
208
+
209
+ /**
210
+ * Due to bug https://bugs.chromium.org/p/chromium/issues/detail?id=678075,
211
+ * it's not reliable to detect if the browser is currently online or offline
212
+ * based on `navigator.onLine`.
213
+ * As a work around, we always assume it's online on first load, and change
214
+ * the status upon `online` or `offline` events.
215
+ */
216
+ var online = true;
217
+ var isOnline = function () { return online; };
218
+ var isDocumentVisible = function () {
219
+ if (typeof document !== 'undefined' &&
220
+ document.visibilityState !== undefined) {
221
+ return document.visibilityState !== 'hidden';
222
+ }
223
+ // always assume it's visible
224
+ return true;
225
+ };
226
+ var fetcher = function (url) { return fetch(url).then(function (res) { return res.json(); }); };
227
+ var registerOnFocus = function (cb) {
228
+ if (typeof window !== 'undefined' &&
229
+ window.addEventListener !== undefined &&
230
+ typeof document !== 'undefined' &&
231
+ document.addEventListener !== undefined) {
232
+ // focus revalidate
233
+ document.addEventListener('visibilitychange', function () { return cb(); }, false);
234
+ window.addEventListener('focus', function () { return cb(); }, false);
235
+ }
236
+ };
237
+ var registerOnReconnect = function (cb) {
238
+ if (typeof window !== 'undefined' && window.addEventListener !== undefined) {
239
+ // reconnect revalidate
240
+ window.addEventListener('online', function () {
241
+ online = true;
242
+ cb();
243
+ }, false);
244
+ // nothing to revalidate, just update the status
245
+ window.addEventListener('offline', function () { return (online = false); }, false);
246
+ }
247
+ };
248
+ var webPreset = {
249
+ isOnline: isOnline,
250
+ isDocumentVisible: isDocumentVisible,
251
+ fetcher: fetcher,
252
+ registerOnFocus: registerOnFocus,
253
+ registerOnReconnect: registerOnReconnect
254
+ };
255
+
256
+ var __assign = (undefined && undefined.__assign) || function () {
257
+ __assign = Object.assign || function(t) {
258
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
259
+ s = arguments[i];
260
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
261
+ t[p] = s[p];
262
+ }
263
+ return t;
264
+ };
265
+ return __assign.apply(this, arguments);
266
+ };
267
+ // cache
268
+ var cache = new Cache();
269
+ // error retry
270
+ function onErrorRetry(_, __, config, revalidate, opts) {
271
+ if (!config.isDocumentVisible()) {
272
+ // if it's hidden, stop
273
+ // it will auto revalidate when focus
274
+ return;
275
+ }
276
+ if (typeof config.errorRetryCount === 'number' &&
277
+ opts.retryCount > config.errorRetryCount) {
278
+ return;
279
+ }
280
+ // exponential backoff
281
+ var count = Math.min(opts.retryCount, 8);
282
+ var timeout = ~~((Math.random() + 0.5) * (1 << count)) * config.errorRetryInterval;
283
+ setTimeout(revalidate, timeout, opts);
284
+ }
285
+ // client side: need to adjust the config
286
+ // based on the browser status
287
+ // slow connection (<= 70Kbps)
288
+ var slowConnection = typeof window !== 'undefined' &&
289
+ // @ts-ignore
290
+ navigator['connection'] &&
291
+ // @ts-ignore
292
+ ['slow-2g', '2g'].indexOf(navigator['connection'].effectiveType) !== -1;
293
+ // config
294
+ var defaultConfig = __assign({
295
+ // events
296
+ onLoadingSlow: function () { }, onSuccess: function () { }, onError: function () { }, onErrorRetry: onErrorRetry, errorRetryInterval: (slowConnection ? 10 : 5) * 1000, focusThrottleInterval: 5 * 1000, dedupingInterval: 2 * 1000, loadingTimeout: (slowConnection ? 5 : 3) * 1000, refreshInterval: 0, revalidateOnFocus: true, revalidateOnReconnect: true, refreshWhenHidden: false, refreshWhenOffline: false, shouldRetryOnError: true, suspense: false, compare: dequal, isPaused: function () { return false; } }, webPreset);
297
+
298
+ var IS_SERVER = typeof window === 'undefined' ||
299
+ // @ts-ignore
300
+ !!(typeof Deno !== 'undefined' && Deno && Deno.version && Deno.version.deno);
301
+ // polyfill for requestAnimationFrame
302
+ var rAF = IS_SERVER
303
+ ? null
304
+ : window['requestAnimationFrame']
305
+ ? function (f) { return window['requestAnimationFrame'](f); }
306
+ : function (f) { return setTimeout(f, 1); };
307
+ // React currently throws a warning when using useLayoutEffect on the server.
308
+ // To get around it, we can conditionally useEffect on the server (no-op) and
309
+ // useLayoutEffect in the browser.
310
+ var useIsomorphicLayoutEffect = IS_SERVER ? useEffect : useLayoutEffect;
311
+
312
+ var SWRConfigContext = createContext({});
313
+ SWRConfigContext.displayName = 'SWRConfigContext';
314
+
315
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
316
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
317
+ return new (P || (P = Promise))(function (resolve, reject) {
318
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
319
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
320
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
321
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
322
+ });
323
+ };
324
+ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
325
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
326
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
327
+ function verb(n) { return function (v) { return step([n, v]); }; }
328
+ function step(op) {
329
+ if (f) throw new TypeError("Generator is already executing.");
330
+ while (_) try {
331
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
332
+ if (y = 0, t) op = [op[0] & 2, t.value];
333
+ switch (op[0]) {
334
+ case 0: case 1: t = op; break;
335
+ case 4: _.label++; return { value: op[1], done: false };
336
+ case 5: _.label++; y = op[1]; op = [0]; continue;
337
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
338
+ default:
339
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
340
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
341
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
342
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
343
+ if (t[2]) _.ops.pop();
344
+ _.trys.pop(); continue;
345
+ }
346
+ op = body.call(thisArg, _);
347
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
348
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
349
+ }
350
+ };
351
+ // global state managers
352
+ var CONCURRENT_PROMISES = {};
353
+ var CONCURRENT_PROMISES_TS = {};
354
+ var FOCUS_REVALIDATORS = {};
355
+ var RECONNECT_REVALIDATORS = {};
356
+ var CACHE_REVALIDATORS = {};
357
+ var MUTATION_TS = {};
358
+ var MUTATION_END_TS = {};
359
+ // generate strictly increasing timestamps
360
+ var now = (function () {
361
+ var ts = 0;
362
+ return function () { return ++ts; };
363
+ })();
364
+ // setup DOM events listeners for `focus` and `reconnect` actions
365
+ if (!IS_SERVER) {
366
+ var revalidate_1 = function (revalidators) {
367
+ if (!defaultConfig.isDocumentVisible() || !defaultConfig.isOnline())
368
+ return;
369
+ for (var key in revalidators) {
370
+ if (revalidators[key][0])
371
+ revalidators[key][0]();
372
+ }
373
+ };
374
+ if (typeof defaultConfig.registerOnFocus === 'function') {
375
+ defaultConfig.registerOnFocus(function () { return revalidate_1(FOCUS_REVALIDATORS); });
376
+ }
377
+ if (typeof defaultConfig.registerOnReconnect === 'function') {
378
+ defaultConfig.registerOnReconnect(function () { return revalidate_1(RECONNECT_REVALIDATORS); });
379
+ }
380
+ }
381
+ var trigger = function (_key, shouldRevalidate) {
382
+ if (shouldRevalidate === void 0) { shouldRevalidate = true; }
383
+ // we are ignoring the second argument which correspond to the arguments
384
+ // the fetcher will receive when key is an array
385
+ var _a = cache.serializeKey(_key), key = _a[0], keyErr = _a[2], keyValidating = _a[3];
386
+ if (!key)
387
+ return Promise.resolve();
388
+ var updaters = CACHE_REVALIDATORS[key];
389
+ if (key && updaters) {
390
+ var currentData = cache.get(key);
391
+ var currentError = cache.get(keyErr);
392
+ var currentIsValidating = cache.get(keyValidating);
393
+ var promises = [];
394
+ for (var i = 0; i < updaters.length; ++i) {
395
+ promises.push(updaters[i](shouldRevalidate, currentData, currentError, currentIsValidating, i > 0));
396
+ }
397
+ // return new updated value
398
+ return Promise.all(promises).then(function () { return cache.get(key); });
399
+ }
400
+ return Promise.resolve(cache.get(key));
401
+ };
402
+ var broadcastState = function (key, data, error, isValidating) {
403
+ var updaters = CACHE_REVALIDATORS[key];
404
+ if (key && updaters) {
405
+ for (var i = 0; i < updaters.length; ++i) {
406
+ updaters[i](false, data, error, isValidating);
407
+ }
408
+ }
409
+ };
410
+ var mutate = function (_key, _data, shouldRevalidate) {
411
+ if (shouldRevalidate === void 0) { shouldRevalidate = true; }
412
+ return __awaiter(void 0, void 0, void 0, function () {
413
+ var _a, key, keyErr, beforeMutationTs, beforeConcurrentPromisesTs, data, error, isAsyncMutation, err_1, shouldAbort, updaters, promises, i;
414
+ return __generator(this, function (_b) {
415
+ switch (_b.label) {
416
+ case 0:
417
+ _a = cache.serializeKey(_key), key = _a[0], keyErr = _a[2];
418
+ if (!key)
419
+ return [2 /*return*/];
420
+ // if there is no new data to update, let's just revalidate the key
421
+ if (typeof _data === 'undefined')
422
+ return [2 /*return*/, trigger(_key, shouldRevalidate)
423
+ // update global timestamps
424
+ ];
425
+ // update global timestamps
426
+ MUTATION_TS[key] = now() - 1;
427
+ MUTATION_END_TS[key] = 0;
428
+ beforeMutationTs = MUTATION_TS[key];
429
+ beforeConcurrentPromisesTs = CONCURRENT_PROMISES_TS[key];
430
+ isAsyncMutation = false;
431
+ if (_data && typeof _data === 'function') {
432
+ // `_data` is a function, call it passing current cache value
433
+ try {
434
+ _data = _data(cache.get(key));
435
+ }
436
+ catch (err) {
437
+ // if `_data` function throws an error synchronously, it shouldn't be cached
438
+ _data = undefined;
439
+ error = err;
440
+ }
441
+ }
442
+ if (!(_data && typeof _data.then === 'function')) return [3 /*break*/, 5];
443
+ // `_data` is a promise
444
+ isAsyncMutation = true;
445
+ _b.label = 1;
446
+ case 1:
447
+ _b.trys.push([1, 3, , 4]);
448
+ return [4 /*yield*/, _data];
449
+ case 2:
450
+ data = _b.sent();
451
+ return [3 /*break*/, 4];
452
+ case 3:
453
+ err_1 = _b.sent();
454
+ error = err_1;
455
+ return [3 /*break*/, 4];
456
+ case 4: return [3 /*break*/, 6];
457
+ case 5:
458
+ data = _data;
459
+ _b.label = 6;
460
+ case 6:
461
+ shouldAbort = function () {
462
+ // check if other mutations have occurred since we've started this mutation
463
+ if (beforeMutationTs !== MUTATION_TS[key] ||
464
+ beforeConcurrentPromisesTs !== CONCURRENT_PROMISES_TS[key]) {
465
+ if (error)
466
+ throw error;
467
+ return true;
468
+ }
469
+ };
470
+ // if there's a race we don't update cache or broadcast change, just return the data
471
+ if (shouldAbort())
472
+ return [2 /*return*/, data];
473
+ if (typeof data !== 'undefined') {
474
+ // update cached data
475
+ cache.set(key, data);
476
+ }
477
+ // always update or reset the error
478
+ cache.set(keyErr, error);
479
+ // reset the timestamp to mark the mutation has ended
480
+ MUTATION_END_TS[key] = now() - 1;
481
+ if (!isAsyncMutation) {
482
+ // we skip broadcasting if there's another mutation happened synchronously
483
+ if (shouldAbort())
484
+ return [2 /*return*/, data];
485
+ }
486
+ updaters = CACHE_REVALIDATORS[key];
487
+ if (updaters) {
488
+ promises = [];
489
+ for (i = 0; i < updaters.length; ++i) {
490
+ promises.push(updaters[i](!!shouldRevalidate, data, error, undefined, i > 0));
491
+ }
492
+ // return new updated value
493
+ return [2 /*return*/, Promise.all(promises).then(function () {
494
+ if (error)
495
+ throw error;
496
+ return cache.get(key);
497
+ })];
498
+ }
499
+ // throw error or return data to be used by caller of mutate
500
+ if (error)
501
+ throw error;
502
+ return [2 /*return*/, data];
503
+ }
504
+ });
505
+ });
506
+ };
507
+ function useSWR() {
508
+ var _this = this;
509
+ var args = [];
510
+ for (var _i = 0; _i < arguments.length; _i++) {
511
+ args[_i] = arguments[_i];
512
+ }
513
+ var _key = args[0];
514
+ var config = Object.assign({}, defaultConfig, useContext(SWRConfigContext), args.length > 2
515
+ ? args[2]
516
+ : args.length === 2 && typeof args[1] === 'object'
517
+ ? args[1]
518
+ : {});
519
+ // in typescript args.length > 2 is not same as args.lenth === 3
520
+ // we do a safe type assertion here
521
+ // args.length === 3
522
+ var fn = (args.length > 2
523
+ ? args[1]
524
+ : args.length === 2 && typeof args[1] === 'function'
525
+ ? args[1]
526
+ : /**
527
+ pass fn as null will disable revalidate
528
+ https://paco.sh/blog/shared-hook-state-with-swr
529
+ */
530
+ args[1] === null
531
+ ? args[1]
532
+ : config.fetcher);
533
+ // we assume `key` as the identifier of the request
534
+ // `key` can change but `fn` shouldn't
535
+ // (because `revalidate` only depends on `key`)
536
+ // `keyErr` is the cache key for error objects
537
+ var _a = cache.serializeKey(_key), key = _a[0], fnArgs = _a[1], keyErr = _a[2], keyValidating = _a[3];
538
+ var configRef = useRef(config);
539
+ useIsomorphicLayoutEffect(function () {
540
+ configRef.current = config;
541
+ });
542
+ var willRevalidateOnMount = function () {
543
+ return (config.revalidateOnMount ||
544
+ (!config.initialData && config.revalidateOnMount === undefined));
545
+ };
546
+ var resolveData = function () {
547
+ var cachedData = cache.get(key);
548
+ return typeof cachedData === 'undefined' ? config.initialData : cachedData;
549
+ };
550
+ var resolveIsValidating = function () {
551
+ return !!cache.get(keyValidating) || (key && willRevalidateOnMount());
552
+ };
553
+ var initialData = resolveData();
554
+ var initialError = cache.get(keyErr);
555
+ var initialIsValidating = resolveIsValidating();
556
+ // if a state is accessed (data, error or isValidating),
557
+ // we add the state to dependencies so if the state is
558
+ // updated in the future, we can trigger a rerender
559
+ var stateDependencies = useRef({
560
+ data: false,
561
+ error: false,
562
+ isValidating: false
563
+ });
564
+ var stateRef = useRef({
565
+ data: initialData,
566
+ error: initialError,
567
+ isValidating: initialIsValidating
568
+ });
569
+ // display the data label in the React DevTools next to SWR hooks
570
+ useDebugValue(stateRef.current.data);
571
+ var rerender = useState({})[1];
572
+ var dispatch = useCallback(function (payload) {
573
+ var shouldUpdateState = false;
574
+ for (var k in payload) {
575
+ // @ts-ignore
576
+ if (stateRef.current[k] === payload[k]) {
577
+ continue;
578
+ }
579
+ // @ts-ignore
580
+ stateRef.current[k] = payload[k];
581
+ // @ts-ignore
582
+ if (stateDependencies.current[k]) {
583
+ shouldUpdateState = true;
584
+ }
585
+ }
586
+ if (shouldUpdateState) {
587
+ // if component is unmounted, should skip rerender
588
+ // if component is not mounted, should skip rerender
589
+ if (unmountedRef.current || !initialMountedRef.current)
590
+ return;
591
+ rerender({});
592
+ }
593
+ },
594
+ // config.suspense isn't allowed to change during the lifecycle
595
+ // eslint-disable-next-line react-hooks/exhaustive-deps
596
+ []);
597
+ // error ref inside revalidate (is last request errored?)
598
+ var unmountedRef = useRef(false);
599
+ var keyRef = useRef(key);
600
+ // check if component is mounted in suspense mode
601
+ var initialMountedRef = useRef(false);
602
+ // do unmount check for callbacks
603
+ var eventsCallback = useCallback(function (event) {
604
+ var _a;
605
+ var params = [];
606
+ for (var _i = 1; _i < arguments.length; _i++) {
607
+ params[_i - 1] = arguments[_i];
608
+ }
609
+ if (unmountedRef.current)
610
+ return;
611
+ if (!initialMountedRef.current)
612
+ return;
613
+ if (key !== keyRef.current)
614
+ return;
615
+ // @ts-ignore
616
+ (_a = configRef.current)[event].apply(_a, params);
617
+ }, [key]);
618
+ var boundMutate = useCallback(function (data, shouldRevalidate) {
619
+ return mutate(keyRef.current, data, shouldRevalidate);
620
+ }, []);
621
+ var addRevalidator = function (revalidators, callback) {
622
+ if (!revalidators[key]) {
623
+ revalidators[key] = [callback];
624
+ }
625
+ else {
626
+ revalidators[key].push(callback);
627
+ }
628
+ return function () {
629
+ var keyedRevalidators = revalidators[key];
630
+ var index = keyedRevalidators.indexOf(callback);
631
+ if (index >= 0) {
632
+ // O(1): faster than splice
633
+ keyedRevalidators[index] =
634
+ keyedRevalidators[keyedRevalidators.length - 1];
635
+ keyedRevalidators.pop();
636
+ }
637
+ };
638
+ };
639
+ // start a revalidation
640
+ var revalidate = useCallback(function (revalidateOpts) {
641
+ if (revalidateOpts === void 0) { revalidateOpts = {}; }
642
+ return __awaiter(_this, void 0, void 0, function () {
643
+ var _a, retryCount, _b, dedupe, loading, shouldDeduping, newData, startAt, newState, err_2;
644
+ return __generator(this, function (_c) {
645
+ switch (_c.label) {
646
+ case 0:
647
+ if (!key || !fn)
648
+ return [2 /*return*/, false];
649
+ if (unmountedRef.current)
650
+ return [2 /*return*/, false];
651
+ if (configRef.current.isPaused())
652
+ return [2 /*return*/, false];
653
+ _a = revalidateOpts.retryCount, retryCount = _a === void 0 ? 0 : _a, _b = revalidateOpts.dedupe, dedupe = _b === void 0 ? false : _b;
654
+ loading = true;
655
+ shouldDeduping = typeof CONCURRENT_PROMISES[key] !== 'undefined' && dedupe;
656
+ _c.label = 1;
657
+ case 1:
658
+ _c.trys.push([1, 6, , 7]);
659
+ dispatch({
660
+ isValidating: true
661
+ });
662
+ cache.set(keyValidating, true);
663
+ if (!shouldDeduping) {
664
+ // also update other hooks
665
+ broadcastState(key, stateRef.current.data, stateRef.current.error, true);
666
+ }
667
+ newData = void 0;
668
+ startAt = void 0;
669
+ if (!shouldDeduping) return [3 /*break*/, 3];
670
+ // there's already an ongoing request,
671
+ // this one needs to be deduplicated.
672
+ startAt = CONCURRENT_PROMISES_TS[key];
673
+ return [4 /*yield*/, CONCURRENT_PROMISES[key]];
674
+ case 2:
675
+ newData = _c.sent();
676
+ return [3 /*break*/, 5];
677
+ case 3:
678
+ // if no cache being rendered currently (it shows a blank page),
679
+ // we trigger the loading slow event.
680
+ if (config.loadingTimeout && !cache.get(key)) {
681
+ setTimeout(function () {
682
+ if (loading)
683
+ eventsCallback('onLoadingSlow', key, config);
684
+ }, config.loadingTimeout);
685
+ }
686
+ if (fnArgs !== null) {
687
+ CONCURRENT_PROMISES[key] = fn.apply(void 0, fnArgs);
688
+ }
689
+ else {
690
+ CONCURRENT_PROMISES[key] = fn(key);
691
+ }
692
+ CONCURRENT_PROMISES_TS[key] = startAt = now();
693
+ return [4 /*yield*/, CONCURRENT_PROMISES[key]];
694
+ case 4:
695
+ newData = _c.sent();
696
+ setTimeout(function () {
697
+ delete CONCURRENT_PROMISES[key];
698
+ delete CONCURRENT_PROMISES_TS[key];
699
+ }, config.dedupingInterval);
700
+ // trigger the success event,
701
+ // only do this for the original request.
702
+ eventsCallback('onSuccess', newData, key, config);
703
+ _c.label = 5;
704
+ case 5:
705
+ // if there're other ongoing request(s), started after the current one,
706
+ // we need to ignore the current one to avoid possible race conditions:
707
+ // req1------------------>res1 (current one)
708
+ // req2---------------->res2
709
+ // the request that fired later will always be kept.
710
+ if (CONCURRENT_PROMISES_TS[key] > startAt) {
711
+ return [2 /*return*/, false];
712
+ }
713
+ // if there're other mutations(s), overlapped with the current revalidation:
714
+ // case 1:
715
+ // req------------------>res
716
+ // mutate------>end
717
+ // case 2:
718
+ // req------------>res
719
+ // mutate------>end
720
+ // case 3:
721
+ // req------------------>res
722
+ // mutate-------...---------->
723
+ // we have to ignore the revalidation result (res) because it's no longer fresh.
724
+ // meanwhile, a new revalidation should be triggered when the mutation ends.
725
+ if (MUTATION_TS[key] &&
726
+ // case 1
727
+ (startAt <= MUTATION_TS[key] ||
728
+ // case 2
729
+ startAt <= MUTATION_END_TS[key] ||
730
+ // case 3
731
+ MUTATION_END_TS[key] === 0)) {
732
+ dispatch({ isValidating: false });
733
+ return [2 /*return*/, false];
734
+ }
735
+ cache.set(keyErr, undefined);
736
+ cache.set(keyValidating, false);
737
+ newState = {
738
+ isValidating: false
739
+ };
740
+ if (typeof stateRef.current.error !== 'undefined') {
741
+ // we don't have an error
742
+ newState.error = undefined;
743
+ }
744
+ if (!config.compare(stateRef.current.data, newData)) {
745
+ // deep compare to avoid extra re-render
746
+ // data changed
747
+ newState.data = newData;
748
+ }
749
+ if (!config.compare(cache.get(key), newData)) {
750
+ cache.set(key, newData);
751
+ }
752
+ // merge the new state
753
+ dispatch(newState);
754
+ if (!shouldDeduping) {
755
+ // also update other hooks
756
+ broadcastState(key, newData, newState.error, false);
757
+ }
758
+ return [3 /*break*/, 7];
759
+ case 6:
760
+ err_2 = _c.sent();
761
+ delete CONCURRENT_PROMISES[key];
762
+ delete CONCURRENT_PROMISES_TS[key];
763
+ if (configRef.current.isPaused()) {
764
+ dispatch({
765
+ isValidating: false
766
+ });
767
+ return [2 /*return*/, false];
768
+ }
769
+ cache.set(keyErr, err_2);
770
+ // get a new error
771
+ // don't use deep equal for errors
772
+ if (stateRef.current.error !== err_2) {
773
+ // we keep the stale data
774
+ dispatch({
775
+ isValidating: false,
776
+ error: err_2
777
+ });
778
+ if (!shouldDeduping) {
779
+ // also broadcast to update other hooks
780
+ broadcastState(key, undefined, err_2, false);
781
+ }
782
+ }
783
+ // events and retry
784
+ eventsCallback('onError', err_2, key, config);
785
+ if (config.shouldRetryOnError) {
786
+ // when retrying, we always enable deduping
787
+ eventsCallback('onErrorRetry', err_2, key, config, revalidate, {
788
+ retryCount: retryCount + 1,
789
+ dedupe: true
790
+ });
791
+ }
792
+ return [3 /*break*/, 7];
793
+ case 7:
794
+ loading = false;
795
+ return [2 /*return*/, true];
796
+ }
797
+ });
798
+ });
799
+ },
800
+ // dispatch is immutable, and `eventsCallback`, `fnArgs`, `keyErr`, and `keyValidating` are based on `key`,
801
+ // so we can them from the deps array.
802
+ //
803
+ // FIXME:
804
+ // `fn` and `config` might be changed during the lifecycle,
805
+ // but they might be changed every render like this.
806
+ // useSWR('key', () => fetch('/api/'), { suspense: true })
807
+ // So we omit the values from the deps array
808
+ // even though it might cause unexpected behaviors.
809
+ // eslint-disable-next-line react-hooks/exhaustive-deps
810
+ [key]);
811
+ // mounted (client side rendering)
812
+ useIsomorphicLayoutEffect(function () {
813
+ if (!key)
814
+ return undefined;
815
+ // after `key` updates, we need to mark it as mounted
816
+ unmountedRef.current = false;
817
+ var isUpdating = initialMountedRef.current;
818
+ initialMountedRef.current = true;
819
+ // after the component is mounted (hydrated),
820
+ // we need to update the data from the cache
821
+ // and trigger a revalidation
822
+ var currentHookData = stateRef.current.data;
823
+ var latestKeyedData = resolveData();
824
+ // update the state if the key changed (not the inital render) or cache updated
825
+ keyRef.current = key;
826
+ if (!config.compare(currentHookData, latestKeyedData)) {
827
+ dispatch({ data: latestKeyedData });
828
+ }
829
+ // revalidate with deduping
830
+ var softRevalidate = function () { return revalidate({ dedupe: true }); };
831
+ // trigger a revalidation
832
+ if (isUpdating || willRevalidateOnMount()) {
833
+ if (typeof latestKeyedData !== 'undefined' && !IS_SERVER) {
834
+ // delay revalidate if there's cache
835
+ // to not block the rendering
836
+ // @ts-ignore it's safe to use requestAnimationFrame in browser
837
+ rAF(softRevalidate);
838
+ }
839
+ else {
840
+ softRevalidate();
841
+ }
842
+ }
843
+ var pending = false;
844
+ var onFocus = function () {
845
+ if (pending || !configRef.current.revalidateOnFocus)
846
+ return;
847
+ pending = true;
848
+ softRevalidate();
849
+ setTimeout(function () { return (pending = false); }, configRef.current.focusThrottleInterval);
850
+ };
851
+ var onReconnect = function () {
852
+ if (configRef.current.revalidateOnReconnect) {
853
+ softRevalidate();
854
+ }
855
+ };
856
+ // register global cache update listener
857
+ var onUpdate = function (shouldRevalidate, updatedData, updatedError, updatedIsValidating, dedupe) {
858
+ if (shouldRevalidate === void 0) { shouldRevalidate = true; }
859
+ if (dedupe === void 0) { dedupe = true; }
860
+ // update hook state
861
+ var newState = {};
862
+ var needUpdate = false;
863
+ if (typeof updatedData !== 'undefined' &&
864
+ !config.compare(stateRef.current.data, updatedData)) {
865
+ newState.data = updatedData;
866
+ needUpdate = true;
867
+ }
868
+ // always update error
869
+ // because it can be `undefined`
870
+ if (stateRef.current.error !== updatedError) {
871
+ newState.error = updatedError;
872
+ needUpdate = true;
873
+ }
874
+ if (typeof updatedIsValidating !== 'undefined' &&
875
+ stateRef.current.isValidating !== updatedIsValidating) {
876
+ newState.isValidating = updatedIsValidating;
877
+ needUpdate = true;
878
+ }
879
+ if (needUpdate) {
880
+ dispatch(newState);
881
+ }
882
+ if (shouldRevalidate) {
883
+ if (dedupe) {
884
+ return softRevalidate();
885
+ }
886
+ else {
887
+ return revalidate();
888
+ }
889
+ }
890
+ return false;
891
+ };
892
+ var unsubFocus = addRevalidator(FOCUS_REVALIDATORS, onFocus);
893
+ var unsubReconnect = addRevalidator(RECONNECT_REVALIDATORS, onReconnect);
894
+ var unsubUpdate = addRevalidator(CACHE_REVALIDATORS, onUpdate);
895
+ return function () {
896
+ // cleanup
897
+ dispatch = function () { return null; };
898
+ // mark it as unmounted
899
+ unmountedRef.current = true;
900
+ unsubFocus();
901
+ unsubReconnect();
902
+ unsubUpdate();
903
+ };
904
+ }, [key, revalidate]);
905
+ useIsomorphicLayoutEffect(function () {
906
+ var timer = null;
907
+ var tick = function () { return __awaiter(_this, void 0, void 0, function () {
908
+ return __generator(this, function (_a) {
909
+ switch (_a.label) {
910
+ case 0:
911
+ if (!(!stateRef.current.error &&
912
+ (configRef.current.refreshWhenHidden ||
913
+ configRef.current.isDocumentVisible()) &&
914
+ (configRef.current.refreshWhenOffline || configRef.current.isOnline()))) return [3 /*break*/, 2];
915
+ // only revalidate when the page is visible
916
+ // if API request errored, we stop polling in this round
917
+ // and let the error retry function handle it
918
+ return [4 /*yield*/, revalidate({ dedupe: true })];
919
+ case 1:
920
+ // only revalidate when the page is visible
921
+ // if API request errored, we stop polling in this round
922
+ // and let the error retry function handle it
923
+ _a.sent();
924
+ _a.label = 2;
925
+ case 2:
926
+ // Read the latest refreshInterval
927
+ if (configRef.current.refreshInterval && timer) {
928
+ timer = setTimeout(tick, configRef.current.refreshInterval);
929
+ }
930
+ return [2 /*return*/];
931
+ }
932
+ });
933
+ }); };
934
+ if (configRef.current.refreshInterval) {
935
+ timer = setTimeout(tick, configRef.current.refreshInterval);
936
+ }
937
+ return function () {
938
+ if (timer) {
939
+ clearTimeout(timer);
940
+ timer = null;
941
+ }
942
+ };
943
+ }, [
944
+ config.refreshInterval,
945
+ config.refreshWhenHidden,
946
+ config.refreshWhenOffline,
947
+ revalidate
948
+ ]);
949
+ // suspense
950
+ var latestData;
951
+ var latestError;
952
+ if (config.suspense) {
953
+ // in suspense mode, we can't return empty state
954
+ // (it should be suspended)
955
+ // try to get data and error from cache
956
+ latestData = cache.get(key);
957
+ latestError = cache.get(keyErr);
958
+ if (typeof latestData === 'undefined') {
959
+ latestData = initialData;
960
+ }
961
+ if (typeof latestError === 'undefined') {
962
+ latestError = initialError;
963
+ }
964
+ if (typeof latestData === 'undefined' &&
965
+ typeof latestError === 'undefined') {
966
+ // need to start the request if it hasn't
967
+ if (!CONCURRENT_PROMISES[key]) {
968
+ // trigger revalidate immediately
969
+ // to get the promise
970
+ // in this revalidate, should not rerender
971
+ revalidate();
972
+ }
973
+ if (CONCURRENT_PROMISES[key] &&
974
+ typeof CONCURRENT_PROMISES[key].then === 'function') {
975
+ // if it is a promise
976
+ throw CONCURRENT_PROMISES[key];
977
+ }
978
+ // it's a value, return it directly (override)
979
+ latestData = CONCURRENT_PROMISES[key];
980
+ }
981
+ if (typeof latestData === 'undefined' && latestError) {
982
+ // in suspense mode, throw error if there's no content
983
+ throw latestError;
984
+ }
985
+ }
986
+ // define returned state
987
+ // can be memorized since the state is a ref
988
+ var memoizedState = useMemo(function () {
989
+ // revalidate will be deprecated in the 1.x release
990
+ // because mutate() covers the same use case of revalidate().
991
+ // This remains only for backward compatibility
992
+ var state = { revalidate: revalidate, mutate: boundMutate };
993
+ Object.defineProperties(state, {
994
+ error: {
995
+ // `key` might be changed in the upcoming hook re-render,
996
+ // but the previous state will stay
997
+ // so we need to match the latest key and data (fallback to `initialData`)
998
+ get: function () {
999
+ stateDependencies.current.error = true;
1000
+ if (config.suspense) {
1001
+ return latestError;
1002
+ }
1003
+ return keyRef.current === key ? stateRef.current.error : initialError;
1004
+ },
1005
+ enumerable: true
1006
+ },
1007
+ data: {
1008
+ get: function () {
1009
+ stateDependencies.current.data = true;
1010
+ if (config.suspense) {
1011
+ return latestData;
1012
+ }
1013
+ return keyRef.current === key ? stateRef.current.data : initialData;
1014
+ },
1015
+ enumerable: true
1016
+ },
1017
+ isValidating: {
1018
+ get: function () {
1019
+ stateDependencies.current.isValidating = true;
1020
+ return key ? stateRef.current.isValidating : false;
1021
+ },
1022
+ enumerable: true
1023
+ }
1024
+ });
1025
+ return state;
1026
+ // `config.suspense` isn't allowed to change during the lifecycle.
1027
+ // `boundMutate` is immutable, and the immutability of `revalidate` depends on `key`
1028
+ // so we can omit them from the deps array,
1029
+ // but we put it to enable react-hooks/exhaustive-deps rule.
1030
+ // `initialData` and `initialError` are not initial values
1031
+ // because they are changed during the lifecycle
1032
+ // so we should add them in the deps array.
1033
+ }, [
1034
+ revalidate,
1035
+ initialData,
1036
+ initialError,
1037
+ boundMutate,
1038
+ key,
1039
+ config.suspense,
1040
+ latestError,
1041
+ latestData
1042
+ ]);
1043
+ return memoizedState;
1044
+ }
1045
+ Object.defineProperty(SWRConfigContext.Provider, 'default', {
1046
+ value: defaultConfig
1047
+ });
1048
+ var SWRConfig = SWRConfigContext.Provider;
1049
+
1050
+ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
1051
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1052
+ return new (P || (P = Promise))(function (resolve, reject) {
1053
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1054
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1055
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1056
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1057
+ });
1058
+ };
1059
+ var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
1060
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
1061
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1062
+ function verb(n) { return function (v) { return step([n, v]); }; }
1063
+ function step(op) {
1064
+ if (f) throw new TypeError("Generator is already executing.");
1065
+ while (_) try {
1066
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1067
+ if (y = 0, t) op = [op[0] & 2, t.value];
1068
+ switch (op[0]) {
1069
+ case 0: case 1: t = op; break;
1070
+ case 4: _.label++; return { value: op[1], done: false };
1071
+ case 5: _.label++; y = op[1]; op = [0]; continue;
1072
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
1073
+ default:
1074
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
1075
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
1076
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
1077
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
1078
+ if (t[2]) _.ops.pop();
1079
+ _.trys.pop(); continue;
1080
+ }
1081
+ op = body.call(thisArg, _);
1082
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
1083
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
1084
+ }
1085
+ };
1086
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
1087
+ var t = {};
1088
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1089
+ t[p] = s[p];
1090
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
1091
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1092
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1093
+ t[p[i]] = s[p[i]];
1094
+ }
1095
+ return t;
1096
+ };
1097
+
49
1098
  var _this = undefined;
50
1099
 
51
1100
  var renderCardImage = function renderCardImage(row, client) {
@@ -1372,64 +2421,57 @@ var QueueDeckExpanded = function QueueDeckExpanded(props) {
1372
2421
  contentCategoryMapping = _props$contentCategor === undefined ? [] : _props$contentCategor,
1373
2422
  showPublished = props.showPublished;
1374
2423
 
1375
- var _useState3 = useState(initialData),
2424
+ var _useState3 = useState(initialCurrentPage || 1),
1376
2425
  _useState4 = _slicedToArray(_useState3, 2),
1377
- data = _useState4[0],
1378
- setData = _useState4[1];
1379
-
1380
- var _useState5 = useState(initialCurrentPage || 1),
1381
- _useState6 = _slicedToArray(_useState5, 2),
1382
- currentPage = _useState6[0],
1383
- setCurrentPage = _useState6[1];
1384
- // const [lastDataSize, setLastDataSize] = useState(initialData ? initialData.length : 0)
1385
- // const [values, setValues] = useState({
1386
- // from: params ? params.from : 0,
1387
- // to: params ? params.to : 0,
1388
- // page: initialCurrentPage ? initialCurrentPage : 1
1389
- // })
2426
+ currentPage = _useState4[0],
2427
+ setCurrentPage = _useState4[1];
1390
2428
 
1391
2429
  var itemsPerPage = params && params.itemsPerPage ? params.itemsPerPage : params && params.from && params.to ? params.to - params.from : 10;
1392
2430
 
1393
- // let prevValues = usePrevious(values)
1394
-
1395
- // check for change in filter parameters from client side and refresh the page
1396
- // useEffect(() => {
1397
- // if (initialData && data !== initialData && initialData.length >= 0) {
1398
- // setData(initialData)
1399
- // setCurrentPage(initialCurrentPage ? initialCurrentPage : 1)
1400
- // setValues({
1401
- // from: params ? params.from : 0,
1402
- // to: params ? params.to : 0,
1403
- // page: initialCurrentPage ? initialCurrentPage : 1
1404
- // })
1405
- // if (initialData.length > 0) {
1406
- // setScrolling(true)
1407
- // }
1408
- // }
1409
- // }, [initialData])
2431
+ var fetcher = function () {
2432
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(currentPage) {
2433
+ var start, params;
2434
+ return regenerator.wrap(function _callee$(_context) {
2435
+ while (1) {
2436
+ switch (_context.prev = _context.next) {
2437
+ case 0:
2438
+ start = (currentPage - 1) * itemsPerPage;
2439
+ params = _extends({}, params, {
2440
+ from: start,
2441
+ to: start + itemsPerPage
2442
+ });
2443
+ _context.next = 4;
2444
+ return client.fetch(query, params);
1410
2445
 
1411
- // useEffect(() => {
1412
- // if (prevValues) {
1413
- // if (values.page !== prevValues.page && values.from !== prevValues.from && values.to !== prevValues.to) {
1414
- // loadData(values, query, client, params, setData, setScrolling, setLastDataSize, pointer, pointerArray)
1415
- // }
1416
- // }
1417
- // }, [values, prevValues, query, client, params, setData, setScrolling, setLastDataSize, pointer, pointerArray])
2446
+ case 4:
2447
+ return _context.abrupt('return', _context.sent);
1418
2448
 
1419
- // useEffect(() => {
1420
- // document.addEventListener('scroll', trackScrolling)
1421
- // return () => {
1422
- // document.removeEventListener('scroll', trackScrolling)
1423
- // }
1424
- // }, [currentPage])
2449
+ case 5:
2450
+ case 'end':
2451
+ return _context.stop();
2452
+ }
2453
+ }
2454
+ }, _callee, _this);
2455
+ }));
1425
2456
 
1426
- // const trackScrolling = (current) => {
1427
- // if (window.pageYOffset === 0) {
1428
- // if (currentPage > 1) {
1429
- // changePageNumber(1, seoPaginate, pageview, router, currentPage, setCurrentPage, itemsPerPage, 1)
1430
- // }
1431
- // }
1432
- // }
2457
+ return function fetcher(_x5) {
2458
+ return _ref4.apply(this, arguments);
2459
+ };
2460
+ }();
2461
+
2462
+ var onLoadDataSuccess = function onLoadDataSuccess() {
2463
+ document.body.scrollTop = 0;
2464
+ document.documentElement.scrollTop = 0;
2465
+ seoPaginate && seoPagination(currentPage);
2466
+ lib_3.refresh();
2467
+ };
2468
+
2469
+ var _useSWR = useSWR([currentPage], fetcher, { initialData: initialData, onSuccess: onLoadDataSuccess }),
2470
+ data = _useSWR.data;
2471
+
2472
+ var handlePageChange = function handlePageChange(selectedPage) {
2473
+ setCurrentPage(selectedPage);
2474
+ };
1433
2475
 
1434
2476
  var seoPagination = function seoPagination(pageNumber) {
1435
2477
  var path = router.asPath;
@@ -1450,69 +2492,13 @@ var QueueDeckExpanded = function QueueDeckExpanded(props) {
1450
2492
  }
1451
2493
  if (queryString.length > 0) path += '?' + queryString;
1452
2494
  pageNumber = parseInt(pageNumber);
1453
- if (currentPage !== pageNumber) {
1454
- if (path[0] !== '/') path = '/' + path;
1455
- var newPath = pageNumber === 1 ? '' + path : '' + path + (queryString.length > 0 ? '&' : '?') + 'page=' + pageNumber;
1456
- router.push(pathname, newPath, {
1457
- shallow: true
1458
- });
1459
- }
2495
+ if (path[0] !== '/') path = '/' + path;
2496
+ var newPath = pageNumber === 1 ? '' + path : '' + path + (queryString.length > 0 ? '&' : '?') + 'page=' + pageNumber;
2497
+ router.push(pathname, newPath, {
2498
+ shallow: true
2499
+ });
1460
2500
  };
1461
2501
 
1462
- var handlePageChange = function () {
1463
- var _ref4 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(selectedPage) {
1464
- var start, newParams, newData;
1465
- return regenerator.wrap(function _callee$(_context) {
1466
- while (1) {
1467
- switch (_context.prev = _context.next) {
1468
- case 0:
1469
- if (!(selectedPage && selectedPage != currentPage)) {
1470
- _context.next = 13;
1471
- break;
1472
- }
1473
-
1474
- start = (selectedPage - 1) * itemsPerPage;
1475
- newParams = _extends({}, params, {
1476
- from: start,
1477
- to: start + itemsPerPage
1478
- });
1479
- _context.prev = 3;
1480
- _context.next = 6;
1481
- return client.fetch(query, newParams);
1482
-
1483
- case 6:
1484
- newData = _context.sent;
1485
-
1486
- if (newData && newData.length > 0) {
1487
- setData(newData);
1488
- document.body.scrollTop = 0;
1489
- document.documentElement.scrollTop = 0;
1490
- seoPaginate && seoPagination(selectedPage);
1491
- setCurrentPage(selectedPage);
1492
- lib_3.refresh();
1493
- }
1494
- _context.next = 13;
1495
- break;
1496
-
1497
- case 10:
1498
- _context.prev = 10;
1499
- _context.t0 = _context['catch'](3);
1500
-
1501
- console.error(_context.t0);
1502
-
1503
- case 13:
1504
- case 'end':
1505
- return _context.stop();
1506
- }
1507
- }
1508
- }, _callee, _this, [[3, 10]]);
1509
- }));
1510
-
1511
- return function handlePageChange(_x5) {
1512
- return _ref4.apply(this, arguments);
1513
- };
1514
- }();
1515
-
1516
2502
  return React__default.createElement(
1517
2503
  'div',
1518
2504
  null,