1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var __spreadArrays = (this && this.__spreadArrays) || function () {
|
7 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
8 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
9 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
10 | r[k] = a[j];
|
11 | return r;
|
12 | };
|
13 |
|
14 | function getCacheId(inputs) {
|
15 | return JSON.stringify(inputs.map(function (input) {
|
16 | return input && typeof input === 'object' ? orderedProps(input) : input;
|
17 | }));
|
18 | }
|
19 | function orderedProps(obj) {
|
20 | return Object.keys(obj)
|
21 | .sort()
|
22 | .map(function (k) {
|
23 | var _a;
|
24 | return (_a = {}, _a[k] = obj[k], _a);
|
25 | });
|
26 | }
|
27 | var memoizeFormatConstructor = function (FormatConstructor, cache) {
|
28 | if (cache === void 0) { cache = {}; }
|
29 | return function () {
|
30 | var _a;
|
31 | var args = [];
|
32 | for (var _i = 0; _i < arguments.length; _i++) {
|
33 | args[_i] = arguments[_i];
|
34 | }
|
35 | var cacheId = getCacheId(args);
|
36 | var format = cacheId && cache[cacheId];
|
37 | if (!format) {
|
38 | format = new ((_a = FormatConstructor).bind.apply(_a, __spreadArrays([void 0], args)))();
|
39 | if (cacheId) {
|
40 | cache[cacheId] = format;
|
41 | }
|
42 | }
|
43 | return format;
|
44 | };
|
45 | };
|
46 | export default memoizeFormatConstructor;
|