@fluentui-react-native/framework-base 0.2.0 → 0.3.0
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/CHANGELOG.json +16 -1
- package/CHANGELOG.md +43 -2
- package/README.md +18 -1
- package/babel.config.js +1 -1
- package/jsx-runtime.js +1 -0
- package/lib/component-patterns/directComponent.d.ts +7 -0
- package/lib/component-patterns/directComponent.d.ts.map +1 -0
- package/lib/component-patterns/directComponent.js +8 -0
- package/lib/component-patterns/directComponent.js.map +1 -0
- package/lib/component-patterns/extract.d.ts +22 -0
- package/lib/component-patterns/extract.d.ts.map +1 -0
- package/lib/component-patterns/extract.js +25 -0
- package/lib/component-patterns/extract.js.map +1 -0
- package/lib/component-patterns/phasedComponent.d.ts +18 -0
- package/lib/component-patterns/phasedComponent.d.ts.map +1 -0
- package/lib/component-patterns/phasedComponent.js +51 -0
- package/lib/component-patterns/phasedComponent.js.map +1 -0
- package/lib/component-patterns/render.d.ts +9 -3
- package/lib/component-patterns/render.d.ts.map +1 -1
- package/lib/component-patterns/render.js +39 -32
- package/lib/component-patterns/render.js.map +1 -1
- package/lib/component-patterns/render.types.d.ts +60 -34
- package/lib/component-patterns/render.types.d.ts.map +1 -1
- package/lib/component-patterns/render.types.js +1 -1
- package/lib/component-patterns/stagedComponent.d.ts +3 -8
- package/lib/component-patterns/stagedComponent.d.ts.map +1 -1
- package/lib/component-patterns/stagedComponent.js +10 -27
- package/lib/component-patterns/stagedComponent.js.map +1 -1
- package/lib/component-patterns/withSlots.d.ts +6 -2
- package/lib/component-patterns/withSlots.d.ts.map +1 -1
- package/lib/component-patterns/withSlots.js +3 -3
- package/lib/component-patterns/withSlots.js.map +1 -1
- package/lib/immutable-merge/Merge.d.ts +6 -3
- package/lib/immutable-merge/Merge.js +79 -83
- package/lib/immutable-merge/Merge.js.map +1 -1
- package/lib/immutable-merge/Merge.test.d.ts +1 -1
- package/lib/immutable-merge/Merge.test.js +231 -219
- package/lib/immutable-merge/Merge.test.js.map +1 -1
- package/lib/index.d.ts +33 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -4
- package/lib/index.js.map +1 -1
- package/lib/jsx-namespace.d.ts +65 -0
- package/lib/jsx-namespace.d.ts.map +1 -0
- package/lib/jsx-namespace.js +2 -0
- package/lib/jsx-namespace.js.map +1 -0
- package/lib/jsx-runtime.d.ts +6 -4
- package/lib/jsx-runtime.d.ts.map +1 -1
- package/lib/jsx-runtime.js +9 -7
- package/lib/jsx-runtime.js.map +1 -1
- package/lib/memo-cache/getCacheEntry.d.ts +13 -13
- package/lib/memo-cache/getCacheEntry.js +20 -22
- package/lib/memo-cache/getCacheEntry.js.map +1 -1
- package/lib/memo-cache/getCacheEntry.test.d.ts +1 -1
- package/lib/memo-cache/getCacheEntry.test.js +90 -90
- package/lib/memo-cache/getCacheEntry.test.js.map +1 -1
- package/lib/memo-cache/getMemoCache.d.ts +1 -1
- package/lib/memo-cache/getMemoCache.js +11 -11
- package/lib/memo-cache/getMemoCache.js.map +1 -1
- package/lib/memo-cache/getMemoCache.test.d.ts +1 -1
- package/lib/memo-cache/getMemoCache.test.js +73 -73
- package/lib/memo-cache/getMemoCache.test.js.map +1 -1
- package/lib/memo-cache/memoize.d.ts +1 -1
- package/lib/memo-cache/memoize.js +9 -9
- package/lib/memo-cache/memoize.js.map +1 -1
- package/lib/memo-cache/memoize.test.d.ts +1 -1
- package/lib/memo-cache/memoize.test.js +36 -38
- package/lib/memo-cache/memoize.test.js.map +1 -1
- package/lib/merge-props/index.d.ts +1 -1
- package/lib/merge-props/index.js +1 -1
- package/lib/merge-props/mergeProps.d.ts +1 -1
- package/lib/merge-props/mergeProps.js +4 -4
- package/lib/merge-props/mergeProps.js.map +1 -1
- package/lib/merge-props/mergeStyles.d.ts +33 -4
- package/lib/merge-props/mergeStyles.d.ts.map +1 -1
- package/lib/merge-props/mergeStyles.js +16 -17
- package/lib/merge-props/mergeStyles.js.map +1 -1
- package/lib/merge-props/mergeStyles.test.d.ts +1 -1
- package/lib/merge-props/mergeStyles.test.js +75 -75
- package/lib/merge-props/mergeStyles.test.js.map +1 -1
- package/lib/merge-props/mergeStyles.types.d.ts +4 -4
- package/lib/merge-props/mergeStyles.types.d.ts.map +1 -1
- package/lib/merge-props/mergeStyles.types.js +1 -1
- package/lib/utilities/filterProps.d.ts +3 -0
- package/lib/utilities/filterProps.d.ts.map +1 -0
- package/lib/utilities/filterProps.js +12 -0
- package/lib/utilities/filterProps.js.map +1 -0
- package/lib-commonjs/component-patterns/directComponent.d.ts +7 -0
- package/lib-commonjs/component-patterns/directComponent.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/directComponent.js +11 -0
- package/lib-commonjs/component-patterns/directComponent.js.map +1 -0
- package/lib-commonjs/component-patterns/extract.d.ts +22 -0
- package/lib-commonjs/component-patterns/extract.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/extract.js +30 -0
- package/lib-commonjs/component-patterns/extract.js.map +1 -0
- package/lib-commonjs/component-patterns/phasedComponent.d.ts +18 -0
- package/lib-commonjs/component-patterns/phasedComponent.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/phasedComponent.js +60 -0
- package/lib-commonjs/component-patterns/phasedComponent.js.map +1 -0
- package/lib-commonjs/component-patterns/render.d.ts +9 -3
- package/lib-commonjs/component-patterns/render.d.ts.map +1 -1
- package/lib-commonjs/component-patterns/render.js +101 -39
- package/lib-commonjs/component-patterns/render.js.map +1 -1
- package/lib-commonjs/component-patterns/render.types.d.ts +60 -34
- package/lib-commonjs/component-patterns/render.types.d.ts.map +1 -1
- package/lib-commonjs/component-patterns/render.types.js +3 -3
- package/lib-commonjs/component-patterns/stagedComponent.d.ts +3 -8
- package/lib-commonjs/component-patterns/stagedComponent.d.ts.map +1 -1
- package/lib-commonjs/component-patterns/stagedComponent.js +64 -34
- package/lib-commonjs/component-patterns/stagedComponent.js.map +1 -1
- package/lib-commonjs/component-patterns/withSlots.d.ts +6 -2
- package/lib-commonjs/component-patterns/withSlots.d.ts.map +1 -1
- package/lib-commonjs/component-patterns/withSlots.js +7 -8
- package/lib-commonjs/component-patterns/withSlots.js.map +1 -1
- package/lib-commonjs/immutable-merge/Merge.d.ts +6 -3
- package/lib-commonjs/immutable-merge/Merge.js +85 -90
- package/lib-commonjs/immutable-merge/Merge.js.map +1 -1
- package/lib-commonjs/immutable-merge/Merge.test.d.ts +1 -1
- package/lib-commonjs/immutable-merge/Merge.test.js +234 -222
- package/lib-commonjs/immutable-merge/Merge.test.js.map +1 -1
- package/lib-commonjs/index.d.ts +33 -5
- package/lib-commonjs/index.d.ts.map +1 -1
- package/lib-commonjs/index.js +184 -31
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/jsx-namespace.d.ts +65 -0
- package/lib-commonjs/jsx-namespace.d.ts.map +1 -0
- package/lib-commonjs/jsx-namespace.js +3 -0
- package/lib-commonjs/jsx-namespace.js.map +1 -0
- package/lib-commonjs/jsx-runtime.d.ts +6 -4
- package/lib-commonjs/jsx-runtime.d.ts.map +1 -1
- package/lib-commonjs/jsx-runtime.js +70 -13
- package/lib-commonjs/jsx-runtime.js.map +1 -1
- package/lib-commonjs/memo-cache/getCacheEntry.d.ts +13 -13
- package/lib-commonjs/memo-cache/getCacheEntry.js +23 -26
- package/lib-commonjs/memo-cache/getCacheEntry.js.map +1 -1
- package/lib-commonjs/memo-cache/getCacheEntry.test.d.ts +1 -1
- package/lib-commonjs/memo-cache/getCacheEntry.test.js +93 -93
- package/lib-commonjs/memo-cache/getCacheEntry.test.js.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.d.ts +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.js +16 -17
- package/lib-commonjs/memo-cache/getMemoCache.js.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.test.d.ts +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.test.js +76 -76
- package/lib-commonjs/memo-cache/getMemoCache.test.js.map +1 -1
- package/lib-commonjs/memo-cache/memoize.d.ts +1 -1
- package/lib-commonjs/memo-cache/memoize.js +13 -14
- package/lib-commonjs/memo-cache/memoize.js.map +1 -1
- package/lib-commonjs/memo-cache/memoize.test.d.ts +1 -1
- package/lib-commonjs/memo-cache/memoize.test.js +39 -41
- package/lib-commonjs/memo-cache/memoize.test.js.map +1 -1
- package/lib-commonjs/merge-props/index.d.ts +1 -1
- package/lib-commonjs/merge-props/index.js +17 -7
- package/lib-commonjs/merge-props/index.js.map +1 -1
- package/lib-commonjs/merge-props/mergeProps.d.ts +1 -1
- package/lib-commonjs/merge-props/mergeProps.js +9 -10
- package/lib-commonjs/merge-props/mergeProps.js.map +1 -1
- package/lib-commonjs/merge-props/mergeStyles.d.ts +33 -4
- package/lib-commonjs/merge-props/mergeStyles.d.ts.map +1 -1
- package/lib-commonjs/merge-props/mergeStyles.js +23 -25
- package/lib-commonjs/merge-props/mergeStyles.js.map +1 -1
- package/lib-commonjs/merge-props/mergeStyles.test.d.ts +1 -1
- package/lib-commonjs/merge-props/mergeStyles.test.js +78 -78
- package/lib-commonjs/merge-props/mergeStyles.test.js.map +1 -1
- package/lib-commonjs/merge-props/mergeStyles.types.d.ts +4 -4
- package/lib-commonjs/merge-props/mergeStyles.types.d.ts.map +1 -1
- package/lib-commonjs/merge-props/mergeStyles.types.js +3 -3
- package/lib-commonjs/utilities/filterProps.d.ts +3 -0
- package/lib-commonjs/utilities/filterProps.d.ts.map +1 -0
- package/lib-commonjs/utilities/filterProps.js +15 -0
- package/lib-commonjs/utilities/filterProps.js.map +1 -0
- package/package.json +48 -20
- package/src/component-patterns/README.md +53 -16
- package/src/component-patterns/directComponent.ts +9 -0
- package/src/component-patterns/extract.ts +32 -0
- package/src/component-patterns/phasedComponent.ts +54 -0
- package/src/component-patterns/render.ts +21 -13
- package/src/component-patterns/render.types.ts +55 -30
- package/src/component-patterns/stagedComponent.ts +24 -0
- package/src/immutable-merge/Merge.test.ts +5 -1
- package/src/index.ts +27 -7
- package/src/jsx-namespace.ts +83 -0
- package/src/jsx-runtime.ts +8 -4
- package/src/memo-cache/README.md +1 -1
- package/src/merge-props/mergeStyles.test.ts +3 -2
- package/src/merge-props/mergeStyles.ts +52 -4
- package/src/merge-props/mergeStyles.types.ts +2 -2
- package/src/utilities/filterProps.ts +14 -0
- package/src/component-patterns/stagedComponent.tsx +0 -45
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const getCacheEntry_1 = require(
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const getCacheEntry_1 = require('./getCacheEntry');
|
|
4
4
|
function compareResults(base, args, argsNoMatch) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const e1 = (0, getCacheEntry_1.getCacheEntry)(base, args);
|
|
6
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, args)).toBe(e1);
|
|
7
|
+
if (argsNoMatch) {
|
|
8
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, argsNoMatch)).not.toBe(e1);
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
describe('Memo cache unit tests', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
12
|
+
test('undefined args to return noargs', () => {
|
|
13
|
+
const base = {};
|
|
14
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, undefined)).toBe(base.noargs);
|
|
15
|
+
});
|
|
16
|
+
test('empty args array to return noargs entry', () => {
|
|
17
|
+
const base = {};
|
|
18
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [])).toBe(base.noargs);
|
|
19
|
+
});
|
|
20
|
+
test('undefined goes to empty entry', () => {
|
|
21
|
+
const base = {};
|
|
22
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [undefined])).toBe(base.empty);
|
|
23
|
+
});
|
|
24
|
+
test('null to go to empty entry', () => {
|
|
25
|
+
const base = {};
|
|
26
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [null])).toBe(base.empty);
|
|
27
|
+
});
|
|
28
|
+
test('string gets keyed correctly', () => {
|
|
29
|
+
const base = {};
|
|
30
|
+
const key = 'foo';
|
|
31
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [key])).toBe(base.str[key]);
|
|
32
|
+
});
|
|
33
|
+
test('number gets keyed correctly', () => {
|
|
34
|
+
const base = {};
|
|
35
|
+
const val = 235;
|
|
36
|
+
const key = val + '';
|
|
37
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [val])).toBe(base.str[key]);
|
|
38
|
+
});
|
|
39
|
+
test('bool gets keyed correctly', () => {
|
|
40
|
+
const base = {};
|
|
41
|
+
const val = true;
|
|
42
|
+
const key = val + '';
|
|
43
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [val])).toBe(base.str[key]);
|
|
44
|
+
});
|
|
45
|
+
test('false bool gets keyed correctly', () => {
|
|
46
|
+
const base = {};
|
|
47
|
+
const val = false;
|
|
48
|
+
const key = val + '';
|
|
49
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [val])).toBe(base.str[key]);
|
|
50
|
+
});
|
|
51
|
+
test('object gets keyed correctly', () => {
|
|
52
|
+
const base = {};
|
|
53
|
+
const key = {};
|
|
54
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [key])).toBe(base.obj.get(key));
|
|
55
|
+
});
|
|
56
|
+
test('function gets keyed correctly', () => {
|
|
57
|
+
const base = {};
|
|
58
|
+
const key = () => {
|
|
59
|
+
return 'hello world';
|
|
60
|
+
};
|
|
61
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [key])).toBe(base.obj.get(key));
|
|
62
|
+
});
|
|
63
|
+
test('basic string retrieval', () => {
|
|
64
|
+
compareResults({}, ['hello', 'world'], ['hello world']);
|
|
65
|
+
});
|
|
66
|
+
test('mixed keys with strings', () => {
|
|
67
|
+
compareResults({}, ['hello', 1, true, undefined, 'world'], ['hello', 1, true, '', 'world']);
|
|
68
|
+
});
|
|
69
|
+
test('basic object matches', () => {
|
|
70
|
+
const obj = {};
|
|
71
|
+
compareResults({}, [obj]);
|
|
72
|
+
});
|
|
73
|
+
test('mixed object and string matches', () => {
|
|
74
|
+
const obj = {};
|
|
75
|
+
compareResults({}, [obj, 'hello', 1, 'world']);
|
|
76
|
+
});
|
|
77
|
+
test('mixed obj and strings with obj at end', () => {
|
|
78
|
+
const obj = {};
|
|
79
|
+
const obj2 = {};
|
|
80
|
+
compareResults({}, ['hello', 1, 'world', obj], ['hello', 1, 'world', obj2]);
|
|
81
|
+
});
|
|
82
|
+
test('hybrid sets', () => {
|
|
83
|
+
const obj = {};
|
|
84
|
+
const obj2 = {};
|
|
85
|
+
compareResults({}, ['hello', obj, 'world', 1, false, obj2, undefined]);
|
|
86
|
+
});
|
|
87
|
+
test('sub cache on object', () => {
|
|
88
|
+
const obj = {};
|
|
89
|
+
const args1 = ['hello', obj];
|
|
90
|
+
const base = {};
|
|
91
|
+
const subRoot = (0, getCacheEntry_1.getCacheEntry)(base, args1);
|
|
92
|
+
const args2 = ['world', base];
|
|
93
|
+
const target = (0, getCacheEntry_1.getCacheEntry)(subRoot, args2);
|
|
94
|
+
expect((0, getCacheEntry_1.getCacheEntry)(base, [...args1, ...args2])).toBe(target);
|
|
95
|
+
});
|
|
96
96
|
});
|
|
97
|
-
//# sourceMappingURL=getCacheEntry.test.js.map
|
|
97
|
+
//# sourceMappingURL=getCacheEntry.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheEntry.test.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.test.ts"],"names":[],"mappings":";;AACA,mDAAgD;AAQhD,SAAS,cAAc,CAAC,IAAe,EAAE,IAAW,EAAE,WAAmB;
|
|
1
|
+
{"version":3,"file":"getCacheEntry.test.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.test.ts"],"names":[],"mappings":";;AACA,mDAAgD;AAQhD,SAAS,cAAc,CAAC,IAAe,EAAE,IAAW,EAAE,WAAmB,EAAQ;IAC/E,MAAM,EAAE,GAAG,IAAA,6BAAa,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACrC,MAAM,CAAC,IAAA,6BAAa,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAE3C,IAAI,WAAW,EAAE,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IAAI,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAAA,CAChE,CAAC,CAAC;AAAA,CACJ,CAAC,CAAC"}
|
|
@@ -20,4 +20,4 @@ export declare function getMemoCache(globalKey?: object): GetMemoValue;
|
|
|
20
20
|
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
21
21
|
*/
|
|
22
22
|
export declare function getTypedMemoCache<T>(globalKey?: object): GetTypedMemoValue<T>;
|
|
23
|
-
//# sourceMappingURL=getMemoCache.d.ts.map
|
|
23
|
+
//# sourceMappingURL=getMemoCache.d.ts.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.getMemoCache = getMemoCache;
|
|
4
|
+
exports.getTypedMemoCache = getTypedMemoCache;
|
|
5
|
+
const getCacheEntry_1 = require('./getCacheEntry');
|
|
5
6
|
/** base node used to remember references when a globalKey is set */
|
|
6
7
|
const _baseEntry = {};
|
|
7
8
|
/**
|
|
@@ -12,12 +13,12 @@ const _baseEntry = {};
|
|
|
12
13
|
* @param keys - an ordered array of values of any type, used as keys to look up the entry
|
|
13
14
|
*/
|
|
14
15
|
function getMemoValueWorker(entry, factory, keys) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const foundEntry = (0, getCacheEntry_1.getCacheEntry)(entry, keys);
|
|
17
|
+
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory
|
|
18
|
+
if (!Object.prototype.hasOwnProperty.call(foundEntry, 'value')) {
|
|
19
|
+
foundEntry.value = typeof factory === 'function' ? factory() : factory;
|
|
20
|
+
}
|
|
21
|
+
return [foundEntry.value, (fact, args) => getMemoValueWorker(foundEntry, fact, args)];
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Get a memo cache instance, this can either be completely self-contained or associated with a global key
|
|
@@ -26,10 +27,9 @@ function getMemoValueWorker(entry, factory, keys) {
|
|
|
26
27
|
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
27
28
|
*/
|
|
28
29
|
function getMemoCache(globalKey) {
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const entry = globalKey ? (0, getCacheEntry_1.getCacheEntry)(_baseEntry, [globalKey]) : {};
|
|
31
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
31
32
|
}
|
|
32
|
-
exports.getMemoCache = getMemoCache;
|
|
33
33
|
/**
|
|
34
34
|
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
35
35
|
*
|
|
@@ -37,8 +37,7 @@ exports.getMemoCache = getMemoCache;
|
|
|
37
37
|
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
38
38
|
*/
|
|
39
39
|
function getTypedMemoCache(globalKey) {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const entry = globalKey ? (0, getCacheEntry_1.getCacheEntry)(_baseEntry, [globalKey]) : {};
|
|
41
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
//# sourceMappingURL=getMemoCache.js.map
|
|
43
|
+
//# sourceMappingURL=getMemoCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":";;;;AACA,mDAAgD;AAYhD,oEAAoE;AACpE,MAAM,UAAU,GAAe,EAAE,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAI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ourceMappingURL=getMemoCache.test.d.ts.map
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const getMemoCache_1 = require(
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const getMemoCache_1 = require('./getMemoCache');
|
|
4
4
|
function getObjFactory() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const obj = { id: 0 };
|
|
6
|
+
return () => ({
|
|
7
|
+
id: obj.id++,
|
|
8
|
+
});
|
|
9
9
|
}
|
|
10
10
|
describe('getMemoCache unit tests', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
11
|
+
test('memoValue with null function', () => {
|
|
12
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
13
|
+
const [val] = memoValue(null, ['foo', 'bar']);
|
|
14
|
+
expect(val).toBeNull();
|
|
15
|
+
});
|
|
16
|
+
test('memoValue with undefined', () => {
|
|
17
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
18
|
+
const [val] = memoValue(undefined, ['foo', 'bar']);
|
|
19
|
+
expect(val).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
test('memoValue with string', () => {
|
|
22
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
23
|
+
const [val] = memoValue('foo', ['bar', 'baz']);
|
|
24
|
+
expect(val).toEqual('foo');
|
|
25
|
+
});
|
|
26
|
+
test('memoValue with object', () => {
|
|
27
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
28
|
+
const obj = { foo: 'hello', bar: 2, baz: 'you' };
|
|
29
|
+
const [val] = memoValue(obj, ['hello', obj]);
|
|
30
|
+
expect(val).toBe(obj);
|
|
31
|
+
});
|
|
32
|
+
test('memoValue executes function', () => {
|
|
33
|
+
const memoValue = (0, getMemoCache_1.getTypedMemoCache)();
|
|
34
|
+
const fn = getObjFactory();
|
|
35
|
+
const v1 = fn();
|
|
36
|
+
const [v2] = memoValue(fn, ['bar', 'baz']);
|
|
37
|
+
expect(v1).not.toBe(v2);
|
|
38
|
+
expect(v1.id).not.toEqual(v2.id);
|
|
39
|
+
});
|
|
40
|
+
test('memo calls function only once', () => {
|
|
41
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
42
|
+
const fn = getObjFactory();
|
|
43
|
+
const keys = ['hello', 'world'];
|
|
44
|
+
const [o1] = memoValue(fn, keys);
|
|
45
|
+
const [o2] = memoValue(fn, keys);
|
|
46
|
+
expect(o2).toBe(o1);
|
|
47
|
+
});
|
|
48
|
+
test('memo calls function only once for empty inputs', () => {
|
|
49
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
50
|
+
const fn = getObjFactory();
|
|
51
|
+
const [o1] = memoValue(fn, undefined);
|
|
52
|
+
const [o2] = memoValue(fn, undefined);
|
|
53
|
+
expect(o2).toBe(o1);
|
|
54
|
+
});
|
|
55
|
+
test('sub caches are separate', () => {
|
|
56
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
57
|
+
const base1 = {};
|
|
58
|
+
const base2 = {};
|
|
59
|
+
const [, getCache1] = memoValue(null, [base1]);
|
|
60
|
+
const [, getCache2] = memoValue(null, [base2]);
|
|
61
|
+
const objKey = {};
|
|
62
|
+
const fn = getObjFactory();
|
|
63
|
+
const [o1] = getCache1(fn, [objKey]);
|
|
64
|
+
const [o2] = getCache2(fn, [objKey]);
|
|
65
|
+
const [o3] = getCache2(fn, [objKey]);
|
|
66
|
+
expect(o1).not.toBe(o2);
|
|
67
|
+
expect(o3).toBe(o2);
|
|
68
|
+
});
|
|
69
|
+
test('sub caches work on branches', () => {
|
|
70
|
+
const memoValue = (0, getMemoCache_1.getMemoCache)();
|
|
71
|
+
const keys1 = [{}, 2, 'hello'];
|
|
72
|
+
const keys2 = [{}, true];
|
|
73
|
+
const fn = getObjFactory();
|
|
74
|
+
const [, getMemoValue] = memoValue(null, keys1);
|
|
75
|
+
const [val1] = getMemoValue(fn, keys2);
|
|
76
|
+
const [val2] = memoValue(fn, [...keys1, ...keys2]);
|
|
77
|
+
expect(val2).toBe(val1);
|
|
78
|
+
});
|
|
79
79
|
});
|
|
80
|
-
//# sourceMappingURL=getMemoCache.test.js.map
|
|
80
|
+
//# sourceMappingURL=getMemoCache.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.test.ts"],"names":[],"mappings":";;AAAA,iDAAiE;AAMjE,SAAS,aAAa;
|
|
1
|
+
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/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MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAAA,CACrB,CAAC,CAAC;IAEH,IAAI,CAAC,6BAA6B,EAAE,GAAG,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAC;QACjC,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;QAC/B,MAAM,KAAK,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACzB,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;QAC3B,MAAM,CAAC,EAAE,YAAY,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAAA,CACzB,CAAC,CAAC;AAAA,CACJ,CAAC,CAAC"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
exports.memoize =
|
|
4
|
-
const getMemoCache_1 = require(
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
exports.memoize = memoize;
|
|
4
|
+
const getMemoCache_1 = require('./getMemoCache');
|
|
5
5
|
/**
|
|
6
6
|
* This wraps a function to memoize the results using the standard javascript memoization pattern
|
|
7
7
|
* @param fn - function to memoize
|
|
8
8
|
*/
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
10
10
|
function memoize(fn) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
// create a unique cache that will be captured in the closure
|
|
12
|
+
const cache = (0, getMemoCache_1.getMemoCache)();
|
|
13
|
+
// create the closure which wraps the calling function
|
|
14
|
+
const closure = (...args) => {
|
|
15
|
+
return cache(() => fn(...(args || [])), args)[0];
|
|
16
|
+
};
|
|
17
|
+
// now return that closure strongly typed as the function.
|
|
18
|
+
return closure;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=memoize.js.map
|
|
20
|
+
//# sourceMappingURL=memoize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,iBAA4C,EAAK,EAAK;IACpD,6DAA6D;IAC7D,MAAM,KAAK,GAAG,IAAA,2BAAY,GAAE,CAAC;IAC7B,sDAAsD;IACtD,MAAM,OAAO,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAAA,CAClD,CAAC;IACF,0DAA0D;IAC1D,OAAO,OAAuB,CAAC;AAAA,CAChC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=memoize.test.d.ts.map
|
|
2
|
+
//# sourceMappingURL=memoize.test.d.ts.map
|
|
@@ -1,47 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
3
|
-
const memoize_1 = require(
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const memoize_1 = require('./memoize');
|
|
4
4
|
let _globalCalls = 0;
|
|
5
5
|
describe('Memoize unit tests', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
const result1 = noArgsFn();
|
|
11
|
-
expect(noArgsFn()).toEqual(result1);
|
|
6
|
+
test('simple function no args', () => {
|
|
7
|
+
const noArgsFn = (0, memoize_1.memoize)(() => {
|
|
8
|
+
return ++_globalCalls;
|
|
12
9
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
incrementFn(3);
|
|
21
|
-
expect(_globalCalls).toEqual(calls);
|
|
22
|
-
incrementFn(4);
|
|
23
|
-
expect(_globalCalls).toEqual(calls + 1);
|
|
24
|
-
incrementFn(4);
|
|
25
|
-
expect(_globalCalls).toEqual(calls + 1);
|
|
10
|
+
const result1 = noArgsFn();
|
|
11
|
+
expect(noArgsFn()).toEqual(result1);
|
|
12
|
+
});
|
|
13
|
+
test('simple function 1 arg', () => {
|
|
14
|
+
const incrementFn = (0, memoize_1.memoize)((bump) => {
|
|
15
|
+
++_globalCalls;
|
|
16
|
+
return bump + 1;
|
|
26
17
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
18
|
+
expect(incrementFn(3)).toEqual(4);
|
|
19
|
+
const calls = _globalCalls;
|
|
20
|
+
incrementFn(3);
|
|
21
|
+
expect(_globalCalls).toEqual(calls);
|
|
22
|
+
incrementFn(4);
|
|
23
|
+
expect(_globalCalls).toEqual(calls + 1);
|
|
24
|
+
incrementFn(4);
|
|
25
|
+
expect(_globalCalls).toEqual(calls + 1);
|
|
26
|
+
});
|
|
27
|
+
test('void function 2 args', () => {
|
|
28
|
+
const voidFn = (0, memoize_1.memoize)((a, b) => {
|
|
29
|
+
if (a) {
|
|
30
|
+
++_globalCalls;
|
|
31
|
+
} else if (b) {
|
|
32
|
+
++_globalCalls;
|
|
33
|
+
} else {
|
|
34
|
+
++_globalCalls;
|
|
35
|
+
}
|
|
45
36
|
});
|
|
37
|
+
voidFn(3, 'hello');
|
|
38
|
+
const calls = _globalCalls;
|
|
39
|
+
voidFn(3, 'hello');
|
|
40
|
+
expect(_globalCalls).toEqual(calls);
|
|
41
|
+
voidFn(3, 'world');
|
|
42
|
+
expect(_globalCalls).toEqual(calls + 1);
|
|
43
|
+
});
|
|
46
44
|
});
|
|
47
|
-
//# sourceMappingURL=memoize.test.js.map
|
|
45
|
+
//# sourceMappingURL=memoize.test.js.map
|