@fluentui-react-native/framework-base 0.1.1 → 0.1.3
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 +31 -1
- package/CHANGELOG.md +18 -2
- package/lib/component-patterns/renderSlot.d.ts +21 -0
- package/lib/component-patterns/renderSlot.d.ts.map +1 -0
- package/lib/component-patterns/renderSlot.js +14 -0
- package/lib/component-patterns/renderSlot.js.map +1 -0
- package/lib/component-patterns/stagedComponent.d.ts +39 -0
- package/lib/component-patterns/stagedComponent.d.ts.map +1 -0
- package/lib/component-patterns/stagedComponent.js +20 -0
- package/lib/component-patterns/stagedComponent.js.map +1 -0
- package/lib/component-patterns/withSlots.d.ts +15 -0
- package/lib/component-patterns/withSlots.d.ts.map +1 -0
- package/lib/component-patterns/withSlots.js +19 -0
- package/lib/component-patterns/withSlots.js.map +1 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/memo-cache/getCacheEntry.d.ts +8 -6
- package/lib/memo-cache/getCacheEntry.d.ts.map +1 -1
- package/lib/memo-cache/getCacheEntry.js +5 -16
- package/lib/memo-cache/getCacheEntry.js.map +1 -1
- package/lib/memo-cache/getMemoCache.d.ts +15 -3
- package/lib/memo-cache/getMemoCache.d.ts.map +1 -1
- package/lib/memo-cache/getMemoCache.js +11 -1
- package/lib/memo-cache/getMemoCache.js.map +1 -1
- package/lib/memo-cache/getMemoCache.test.js +2 -2
- package/lib/memo-cache/getMemoCache.test.js.map +1 -1
- package/lib/memo-cache/memoize.js.map +1 -1
- package/lib-commonjs/component-patterns/renderSlot.d.ts +21 -0
- package/lib-commonjs/component-patterns/renderSlot.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/renderSlot.js +19 -0
- package/lib-commonjs/component-patterns/renderSlot.js.map +1 -0
- package/lib-commonjs/component-patterns/stagedComponent.d.ts +39 -0
- package/lib-commonjs/component-patterns/stagedComponent.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/stagedComponent.js +25 -0
- package/lib-commonjs/component-patterns/stagedComponent.js.map +1 -0
- package/lib-commonjs/component-patterns/withSlots.d.ts +15 -0
- package/lib-commonjs/component-patterns/withSlots.d.ts.map +1 -0
- package/lib-commonjs/component-patterns/withSlots.js +23 -0
- package/lib-commonjs/component-patterns/withSlots.js.map +1 -0
- package/lib-commonjs/index.d.ts +7 -2
- package/lib-commonjs/index.d.ts.map +1 -1
- package/lib-commonjs/index.js +9 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/memo-cache/getCacheEntry.d.ts +8 -6
- package/lib-commonjs/memo-cache/getCacheEntry.d.ts.map +1 -1
- package/lib-commonjs/memo-cache/getCacheEntry.js +5 -16
- package/lib-commonjs/memo-cache/getCacheEntry.js.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.d.ts +15 -3
- package/lib-commonjs/memo-cache/getMemoCache.d.ts.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.js +13 -2
- package/lib-commonjs/memo-cache/getMemoCache.js.map +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.test.js +1 -1
- package/lib-commonjs/memo-cache/getMemoCache.test.js.map +1 -1
- package/lib-commonjs/memo-cache/memoize.js.map +1 -1
- package/package.json +1 -16
- package/src/component-patterns/renderSlot.ts +27 -0
- package/src/component-patterns/stagedComponent.ts +53 -0
- package/src/component-patterns/withSlots.tsx +25 -0
- package/src/index.ts +9 -2
- package/src/memo-cache/getCacheEntry.ts +17 -25
- package/src/memo-cache/getMemoCache.test.ts +2 -2
- package/src/memo-cache/getMemoCache.ts +24 -8
- package/src/memo-cache/memoize.ts +2 -2
- package/lib/memo-cache/index.d.ts +0 -4
- package/lib/memo-cache/index.d.ts.map +0 -1
- package/lib/memo-cache/index.js +0 -3
- package/lib/memo-cache/index.js.map +0 -1
- package/lib-commonjs/memo-cache/index.d.ts +0 -4
- package/lib-commonjs/memo-cache/index.d.ts.map +0 -1
- package/lib-commonjs/memo-cache/index.js +0 -8
- package/lib-commonjs/memo-cache/index.js.map +0 -1
- package/src/memo-cache/index.ts +0 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NativeReactType } from './renderSlot';
|
|
2
|
+
/**
|
|
3
|
+
* This function is required for any module that uses slots.
|
|
4
|
+
*
|
|
5
|
+
* This function is a slot resolver that automatically evaluates slot functions to generate React elements.
|
|
6
|
+
* A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
|
|
7
|
+
*
|
|
8
|
+
* To use this function on a per-file basis, use the jsx directive targeting withSlots.
|
|
9
|
+
* This directive must be the FIRST LINE in the file to work correctly.
|
|
10
|
+
* Usage of this pragma also requires withSlots import statement.
|
|
11
|
+
*
|
|
12
|
+
* See React.createElement
|
|
13
|
+
*/
|
|
14
|
+
export declare function withSlots<P>(reactType: NativeReactType, props?: (React.Attributes & P) | null, ...children: React.ReactNode[]): ReturnType<React.FunctionComponent<P>>;
|
|
15
|
+
//# sourceMappingURL=withSlots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withSlots.d.ts","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;;;GAWG;AAGH,wBAAgB,SAAS,CAAC,CAAC,EACzB,SAAS,EAAE,eAAe,EAC1B,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,IAAI,EACrC,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,GAC7B,UAAU,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAGxC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withSlots = void 0;
|
|
4
|
+
const renderSlot_1 = require("./renderSlot");
|
|
5
|
+
/**
|
|
6
|
+
* This function is required for any module that uses slots.
|
|
7
|
+
*
|
|
8
|
+
* This function is a slot resolver that automatically evaluates slot functions to generate React elements.
|
|
9
|
+
* A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
|
|
10
|
+
*
|
|
11
|
+
* To use this function on a per-file basis, use the jsx directive targeting withSlots.
|
|
12
|
+
* This directive must be the FIRST LINE in the file to work correctly.
|
|
13
|
+
* Usage of this pragma also requires withSlots import statement.
|
|
14
|
+
*
|
|
15
|
+
* See React.createElement
|
|
16
|
+
*/
|
|
17
|
+
// Can't use typeof on React.createElement since it's overloaded. Approximate createElement's signature for now and widen as needed.
|
|
18
|
+
function withSlots(reactType, props, ...children) {
|
|
19
|
+
// if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
|
|
20
|
+
return (0, renderSlot_1.renderSlot)(reactType, props, ...children);
|
|
21
|
+
}
|
|
22
|
+
exports.withSlots = withSlots;
|
|
23
|
+
//# sourceMappingURL=withSlots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withSlots.js","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C;;;;;;;;;;;GAWG;AAEH,oIAAoI;AACpI,SAAgB,SAAS,CACvB,SAA0B,EAC1B,KAAqC,EACrC,GAAG,QAA2B;IAE9B,0HAA0H;IAC1H,OAAO,IAAA,uBAAU,EAAI,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;AACtD,CAAC;AAPD,8BAOC"}
|
package/lib-commonjs/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
export { immutableMerge, immutableMergeCore, processImmutable, filterToObjects } from './immutable-merge/Merge';
|
|
2
2
|
export type { BuiltinRecursionHandlers, CustomRecursionHandler, MergeOptions, ObjectBase, RecursionHandler, RecursionOption, } from './immutable-merge/Merge';
|
|
3
|
-
export type { GetMemoValue } from './memo-cache/getMemoCache';
|
|
4
|
-
export { getMemoCache } from './memo-cache/getMemoCache';
|
|
3
|
+
export type { GetMemoValue, GetTypedMemoValue } from './memo-cache/getMemoCache';
|
|
4
|
+
export { getMemoCache, getTypedMemoCache } from './memo-cache/getMemoCache';
|
|
5
5
|
export { memoize } from './memo-cache/memoize';
|
|
6
6
|
export type { StyleProp } from './merge-props/mergeStyles.types';
|
|
7
7
|
export { mergeStyles } from './merge-props/mergeStyles';
|
|
8
8
|
export { mergeProps } from './merge-props/mergeProps';
|
|
9
|
+
export { renderSlot } from './component-patterns/renderSlot';
|
|
10
|
+
export type { SlotFn, NativeReactType } from './component-patterns/renderSlot';
|
|
11
|
+
export { withSlots } from './component-patterns/withSlots';
|
|
12
|
+
export { stagedComponent } from './component-patterns/stagedComponent';
|
|
13
|
+
export type { FinalRender, StagedRender, ComposableFunction } from './component-patterns/stagedComponent';
|
|
9
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAChH,YAAY,EACV,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,YAAY,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeProps = exports.mergeStyles = exports.memoize = exports.getMemoCache = exports.filterToObjects = exports.processImmutable = exports.immutableMergeCore = exports.immutableMerge = void 0;
|
|
3
|
+
exports.stagedComponent = exports.withSlots = exports.renderSlot = exports.mergeProps = exports.mergeStyles = exports.memoize = exports.getTypedMemoCache = exports.getMemoCache = exports.filterToObjects = exports.processImmutable = exports.immutableMergeCore = exports.immutableMerge = void 0;
|
|
4
4
|
// immutable-merge exports
|
|
5
5
|
var Merge_1 = require("./immutable-merge/Merge");
|
|
6
6
|
Object.defineProperty(exports, "immutableMerge", { enumerable: true, get: function () { return Merge_1.immutableMerge; } });
|
|
@@ -9,10 +9,18 @@ Object.defineProperty(exports, "processImmutable", { enumerable: true, get: func
|
|
|
9
9
|
Object.defineProperty(exports, "filterToObjects", { enumerable: true, get: function () { return Merge_1.filterToObjects; } });
|
|
10
10
|
var getMemoCache_1 = require("./memo-cache/getMemoCache");
|
|
11
11
|
Object.defineProperty(exports, "getMemoCache", { enumerable: true, get: function () { return getMemoCache_1.getMemoCache; } });
|
|
12
|
+
Object.defineProperty(exports, "getTypedMemoCache", { enumerable: true, get: function () { return getMemoCache_1.getTypedMemoCache; } });
|
|
12
13
|
var memoize_1 = require("./memo-cache/memoize");
|
|
13
14
|
Object.defineProperty(exports, "memoize", { enumerable: true, get: function () { return memoize_1.memoize; } });
|
|
14
15
|
var mergeStyles_1 = require("./merge-props/mergeStyles");
|
|
15
16
|
Object.defineProperty(exports, "mergeStyles", { enumerable: true, get: function () { return mergeStyles_1.mergeStyles; } });
|
|
16
17
|
var mergeProps_1 = require("./merge-props/mergeProps");
|
|
17
18
|
Object.defineProperty(exports, "mergeProps", { enumerable: true, get: function () { return mergeProps_1.mergeProps; } });
|
|
19
|
+
// component pattern exports
|
|
20
|
+
var renderSlot_1 = require("./component-patterns/renderSlot");
|
|
21
|
+
Object.defineProperty(exports, "renderSlot", { enumerable: true, get: function () { return renderSlot_1.renderSlot; } });
|
|
22
|
+
var withSlots_1 = require("./component-patterns/withSlots");
|
|
23
|
+
Object.defineProperty(exports, "withSlots", { enumerable: true, get: function () { return withSlots_1.withSlots; } });
|
|
24
|
+
var stagedComponent_1 = require("./component-patterns/stagedComponent");
|
|
25
|
+
Object.defineProperty(exports, "stagedComponent", { enumerable: true, get: function () { return stagedComponent_1.stagedComponent; } });
|
|
18
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,iDAAgH;AAAvG,uGAAA,cAAc,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAY9E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AAC1B,iDAAgH;AAAvG,uGAAA,cAAc,OAAA;AAAE,2GAAA,kBAAkB,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,wGAAA,eAAe,OAAA;AAY9E,0DAA4E;AAAnE,4GAAA,YAAY,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AACxC,gDAA+C;AAAtC,kGAAA,OAAO,OAAA;AAIhB,yDAAwD;AAA/C,0GAAA,WAAW,OAAA;AACpB,uDAAsD;AAA7C,wGAAA,UAAU,OAAA;AAEnB,4BAA4B;AAC5B,8DAA6D;AAApD,wGAAA,UAAU,OAAA;AAEnB,4DAA2D;AAAlD,sGAAA,SAAS,OAAA;AAClB,wEAAuE;AAA9D,kHAAA,eAAe,OAAA"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/** signature for the object/function key values, used for memoization */
|
|
2
|
+
export type MemoObjectKey = object | Function;
|
|
3
|
+
export type CacheEntry<T = unknown> = {
|
|
2
4
|
/** stores the cached value if any */
|
|
3
5
|
value?: T;
|
|
4
6
|
/** entry used for undefined and null values, these both collapse to the same type */
|
|
5
|
-
empty?: CacheEntry<
|
|
7
|
+
empty?: CacheEntry<T>;
|
|
6
8
|
/** entry used for the case where the array of args is null or length 0 */
|
|
7
|
-
noargs?: CacheEntry<
|
|
9
|
+
noargs?: CacheEntry<T>;
|
|
8
10
|
/** all remaining non-object types are keyed as strings for lookups */
|
|
9
11
|
str?: {
|
|
10
|
-
[key: string]: CacheEntry<
|
|
12
|
+
[key: string]: CacheEntry<T>;
|
|
11
13
|
};
|
|
12
14
|
/** object types are keyed in a weak map on object identity */
|
|
13
|
-
obj?: WeakMap<
|
|
15
|
+
obj?: WeakMap<MemoObjectKey, CacheEntry<T>>;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
18
|
* Given a base entry, either traverse or build the cache tree that matches the provided args
|
|
@@ -18,5 +20,5 @@ export type CacheEntry<T, TGet = any> = {
|
|
|
18
20
|
* @param entry - entry to use as the base of the cache walk
|
|
19
21
|
* @param args - array of arguments to use to progress deeper into the cache
|
|
20
22
|
*/
|
|
21
|
-
export declare function getCacheEntry
|
|
23
|
+
export declare function getCacheEntry(entry: CacheEntry, args: unknown[]): CacheEntry;
|
|
22
24
|
//# sourceMappingURL=getCacheEntry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheEntry.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"getCacheEntry.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE9C,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI;IACpC,qCAAqC;IACrC,KAAK,CAAC,EAAE,CAAC,CAAC;IAEV,qFAAqF;IACrF,KAAK,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEtB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEvB,sEAAsE;IACtE,GAAG,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;KAAE,CAAC;IAEvC,8DAA8D;IAC9D,GAAG,CAAC,EAAE,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAC7C,CAAC;AA0BF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAO5E"}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCacheEntry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* just wraps the common entry.foo = entry.foo || {} pattern
|
|
6
|
-
* @param entry - entry to ensure a key value for
|
|
7
|
-
* @param key - which key of that entry to ensure the value for
|
|
8
|
-
*/
|
|
9
|
-
function ensureAndReturn(entry, key) {
|
|
10
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
11
|
-
throw new Error('Invalid key');
|
|
12
|
-
}
|
|
13
|
-
return (entry[key] = entry[key] || {});
|
|
14
|
-
}
|
|
15
4
|
/**
|
|
16
5
|
* Step one level deeper in the cache, based on the key value from the current location
|
|
17
6
|
*
|
|
@@ -23,17 +12,17 @@ function jumpToCacheEntry(entry, val) {
|
|
|
23
12
|
// undefined or null just routes directly to the empty object. This avoids the issues of string collisions with 'null' or 'undefined'
|
|
24
13
|
// when using the string key map, it also avoids creating the WeakMap (since null is technically typoef object), particularly in cases
|
|
25
14
|
// where null is just being set on non-object types.
|
|
26
|
-
return
|
|
15
|
+
return (entry.empty ??= {});
|
|
27
16
|
}
|
|
28
17
|
if (typeof val === 'object' || typeof val === 'function') {
|
|
29
18
|
// objects and functions will be treated as key values in a WeakMap
|
|
30
|
-
const byObj = (entry.obj
|
|
19
|
+
const byObj = (entry.obj ??= new WeakMap());
|
|
31
20
|
return byObj.get(val) || byObj.set(val, {}).get(val);
|
|
32
21
|
}
|
|
33
22
|
// otherwise convert everything to a string and store it in the str object (using it as a map)
|
|
34
23
|
const key = val + '';
|
|
35
|
-
const byString =
|
|
36
|
-
return (byString[key]
|
|
24
|
+
const byString = (entry.str ??= {});
|
|
25
|
+
return (byString[key] ??= {});
|
|
37
26
|
}
|
|
38
27
|
/**
|
|
39
28
|
* Given a base entry, either traverse or build the cache tree that matches the provided args
|
|
@@ -47,7 +36,7 @@ function getCacheEntry(entry, args) {
|
|
|
47
36
|
// - otherwise if there are no args just use the noargs branch
|
|
48
37
|
return args && args.length > 0
|
|
49
38
|
? args.reduce((previous, arg) => jumpToCacheEntry(previous, arg), entry)
|
|
50
|
-
:
|
|
39
|
+
: (entry.noargs ??= {});
|
|
51
40
|
}
|
|
52
41
|
exports.getCacheEntry = getCacheEntry;
|
|
53
42
|
//# sourceMappingURL=getCacheEntry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCacheEntry.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getCacheEntry.js","sourceRoot":"","sources":["../../src/memo-cache/getCacheEntry.ts"],"names":[],"mappings":";;;AAqBA;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAiB,EAAE,GAAQ;IACnD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;QACrC,sIAAsI;QACtI,sIAAsI;QACtI,oDAAoD;QACpD,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;KAC7B;IACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;QACxD,mEAAmE;QACnE,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,IAAI,OAAO,EAA6B,CAAC,CAAC;QACvE,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KACtD;IACD,8FAA8F;IAC9F,MAAM,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;IACrB,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,KAAiB,EAAE,IAAe;IAC9D,6DAA6D;IAC7D,8GAA8G;IAC9G,8DAA8D;IAC9D,OAAO,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAC5B,CAAC,CAAE,IAAI,CAAC,MAAM,CAAC,CAAC,QAAoB,EAAE,GAAY,EAAE,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,KAAK,CAAgB;QAC7G,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC;AAC5B,CAAC;AAPD,sCAOC"}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
export type ValueFactory<T> = () => T;
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Signature for the cache function. While the implementation is generic, it can run in two modes:
|
|
4
|
+
* - Typed: the cache will enforce the type of both the factory and returned value
|
|
5
|
+
* - Untyped: the cache will infer the type on each call from the factory return value
|
|
6
|
+
*/
|
|
7
|
+
export type GetTypedMemoValue<T> = (factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetTypedMemoValue<T>];
|
|
8
|
+
export type GetMemoValue = <T>(factory: T | ValueFactory<T>, keys: unknown[]) => [T, GetMemoValue];
|
|
4
9
|
/**
|
|
5
10
|
* Get a memo cache instance, this can either be completely self-contained or associated with a global key
|
|
6
11
|
*
|
|
7
12
|
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
8
13
|
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
9
14
|
*/
|
|
10
|
-
export declare function getMemoCache
|
|
15
|
+
export declare function getMemoCache(globalKey?: object): GetMemoValue;
|
|
16
|
+
/**
|
|
17
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
18
|
+
*
|
|
19
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
20
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getTypedMemoCache<T>(globalKey?: object): GetTypedMemoValue<T>;
|
|
11
23
|
//# sourceMappingURL=getMemoCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEtC
|
|
1
|
+
{"version":3,"file":"getMemoCache.d.ts","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEtC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAChH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAqBnG;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CAG7D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAG7E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMemoCache = void 0;
|
|
3
|
+
exports.getTypedMemoCache = exports.getMemoCache = void 0;
|
|
4
4
|
const getCacheEntry_1 = require("./getCacheEntry");
|
|
5
5
|
/** base node used to remember references when a globalKey is set */
|
|
6
6
|
const _baseEntry = {};
|
|
@@ -14,7 +14,7 @@ const _baseEntry = {};
|
|
|
14
14
|
function getMemoValueWorker(entry, factory, keys) {
|
|
15
15
|
const foundEntry = (0, getCacheEntry_1.getCacheEntry)(entry, keys);
|
|
16
16
|
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory
|
|
17
|
-
if (!
|
|
17
|
+
if (!Object.prototype.hasOwnProperty.call(foundEntry, 'value')) {
|
|
18
18
|
foundEntry.value = typeof factory === 'function' ? factory() : factory;
|
|
19
19
|
}
|
|
20
20
|
return [foundEntry.value, (fact, args) => getMemoValueWorker(foundEntry, fact, args)];
|
|
@@ -30,4 +30,15 @@ function getMemoCache(globalKey) {
|
|
|
30
30
|
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
31
31
|
}
|
|
32
32
|
exports.getMemoCache = getMemoCache;
|
|
33
|
+
/**
|
|
34
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
35
|
+
*
|
|
36
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
37
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
38
|
+
*/
|
|
39
|
+
function getTypedMemoCache(globalKey) {
|
|
40
|
+
const entry = globalKey ? (0, getCacheEntry_1.getCacheEntry)(_baseEntry, [globalKey]) : {};
|
|
41
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
42
|
+
}
|
|
43
|
+
exports.getTypedMemoCache = getTypedMemoCache;
|
|
33
44
|
//# sourceMappingURL=getMemoCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":";;;AACA,mDAAgD;
|
|
1
|
+
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":";;;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AAC;AAHD,8CAGC"}
|
|
@@ -30,7 +30,7 @@ describe('getMemoCache unit tests', () => {
|
|
|
30
30
|
expect(val).toBe(obj);
|
|
31
31
|
});
|
|
32
32
|
test('memoValue executes function', () => {
|
|
33
|
-
const memoValue = (0, getMemoCache_1.
|
|
33
|
+
const memoValue = (0, getMemoCache_1.getTypedMemoCache)();
|
|
34
34
|
const fn = getObjFactory();
|
|
35
35
|
const v1 = fn();
|
|
36
36
|
const [v2] = memoValue(fn, ['bar', 'baz']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.test.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.test.ts"],"names":[],"mappings":";;AAAA,iDAAiE;AAMjE,SAAS,aAAa;IACpB,MAAM,GAAG,GAAY,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAC/B,OAAO,GAAG,EAAE,CAAC,CAAC;QACZ,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE;KACb,CAAC,CAAC;AACL,CAAC;AAED,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACxC,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QAC9C,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACpC,MAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,KAA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.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,SAAgB,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,IAAA,2BAAY,
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,SAAgB,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,IAAA,2BAAY,GAAE,CAAC;IAC7B,sDAAsD;IACtD,MAAM,OAAO,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;QACrC,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC;IACF,0DAA0D;IAC1D,OAAO,OAAuB,CAAC;AACjC,CAAC;AATD,0BASC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui-react-native/framework-base",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Base types and utilities fluentui-react-native frameworks",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,21 +16,6 @@
|
|
|
16
16
|
"import": "./lib/index.js",
|
|
17
17
|
"require": "./lib-commonjs/index.js",
|
|
18
18
|
"types": "./lib/index.d.ts"
|
|
19
|
-
},
|
|
20
|
-
"./immutable-merge": {
|
|
21
|
-
"import": "./lib/immutable-merge/Merge.js",
|
|
22
|
-
"require": "./lib-commonjs/immutable-merge/Merge.js",
|
|
23
|
-
"types": "./lib/immutable-merge/Merge.d.ts"
|
|
24
|
-
},
|
|
25
|
-
"./memo-cache": {
|
|
26
|
-
"import": "./lib/memo-cache/index.js",
|
|
27
|
-
"require": "./lib-commonjs/memo-cache/index.js",
|
|
28
|
-
"types": "./lib/memo-cache/index.d.ts"
|
|
29
|
-
},
|
|
30
|
-
"./merge-props": {
|
|
31
|
-
"import": "./lib/merge-props/index.js",
|
|
32
|
-
"require": "./lib-commonjs/merge-props/index.js",
|
|
33
|
-
"types": "./lib/merge-props/lib/index.d.ts"
|
|
34
19
|
}
|
|
35
20
|
},
|
|
36
21
|
"scripts": {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Component slots have a marker which allows the slot render handler to know which ones are safe to call as a function.
|
|
5
|
+
*/
|
|
6
|
+
export type SlotFn<TProps> = React.FunctionComponent<TProps> & {
|
|
7
|
+
_canCompose?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The standard element type inputs for react and react-native. This might be View or Button, or it might be 'div' in web. Effectively
|
|
12
|
+
* it is what react accepts for React.createElement
|
|
13
|
+
*/
|
|
14
|
+
export type NativeReactType = React.ElementType<any> | string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Renders a slot
|
|
18
|
+
*
|
|
19
|
+
* @param slot - native react type or slot function to render
|
|
20
|
+
* @param extraProps - additional props to mixin
|
|
21
|
+
* @param children - the children to pass down to the slot
|
|
22
|
+
*/
|
|
23
|
+
export function renderSlot<TProps>(slot: NativeReactType | SlotFn<TProps>, extraProps: TProps, ...children: React.ReactNode[]) {
|
|
24
|
+
return typeof slot === 'function' && (slot as SlotFn<TProps>)._canCompose
|
|
25
|
+
? (slot as SlotFn<TProps>)(extraProps, ...children)
|
|
26
|
+
: React.createElement(slot, extraProps, ...children);
|
|
27
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The final rendering of the props in a staged render. This is the function component signature that matches that of
|
|
5
|
+
* React.createElement, children (if present) will be part of the variable args at the end.
|
|
6
|
+
*/
|
|
7
|
+
export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => JSX.Element | null;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This is a pattern of rendering where a functional component can be executed in two stages rather than in a single pass.
|
|
11
|
+
*
|
|
12
|
+
* The pattern looks like:
|
|
13
|
+
* (props) => {
|
|
14
|
+
* // handle props
|
|
15
|
+
* // call hooks, remember these can't be conditional
|
|
16
|
+
* // build styles and props to pass to child components
|
|
17
|
+
*
|
|
18
|
+
* return (additionalProps, ...children) => {
|
|
19
|
+
* // return the actual element tree, this includes conditional branching or rendering
|
|
20
|
+
* // mixin additional props, props which require logic should be required in phase 1.
|
|
21
|
+
*
|
|
22
|
+
* // NOTE: This is where children will show up
|
|
23
|
+
* };
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export type StagedRender<TProps> = (props: TProps, ...args: any[]) => FinalRender<TProps>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A composable function may have a two stage render function as an attached property. This allows the function to work
|
|
31
|
+
* in all the standard react flows, but allows for pulling out the staged render when components understand it.
|
|
32
|
+
*/
|
|
33
|
+
export type ComposableFunction<TProps> = React.FunctionComponent<TProps> & { _staged?: StagedRender<TProps> };
|
|
34
|
+
|
|
35
|
+
function asArray<T>(val: T | T[]): T[] {
|
|
36
|
+
return Array.isArray(val) ? val : [val];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Take a staged render function and make a real component out of it
|
|
41
|
+
*
|
|
42
|
+
* @param staged - staged render function to wrap into a staged component
|
|
43
|
+
* @param memo - optional flag to enable wrapping the created component in a React.memo HOC
|
|
44
|
+
*/
|
|
45
|
+
export function stagedComponent<TProps>(staged: StagedRender<TProps>, memo?: boolean): ComposableFunction<TProps> {
|
|
46
|
+
const component = (props: React.PropsWithChildren<TProps>) => {
|
|
47
|
+
const { children, ...rest } = props;
|
|
48
|
+
return staged(rest as TProps)({} as React.PropsWithChildren<TProps>, asArray(children));
|
|
49
|
+
};
|
|
50
|
+
const stagedComponent = memo ? React.memo(component) : component;
|
|
51
|
+
Object.assign(stagedComponent, { _staged: staged });
|
|
52
|
+
return stagedComponent as ComposableFunction<TProps>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { NativeReactType } from './renderSlot';
|
|
2
|
+
import { renderSlot } from './renderSlot';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This function is required for any module that uses slots.
|
|
6
|
+
*
|
|
7
|
+
* This function is a slot resolver that automatically evaluates slot functions to generate React elements.
|
|
8
|
+
* A byproduct of this resolver is that it removes slots from the React hierarchy by bypassing React.createElement.
|
|
9
|
+
*
|
|
10
|
+
* To use this function on a per-file basis, use the jsx directive targeting withSlots.
|
|
11
|
+
* This directive must be the FIRST LINE in the file to work correctly.
|
|
12
|
+
* Usage of this pragma also requires withSlots import statement.
|
|
13
|
+
*
|
|
14
|
+
* See React.createElement
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Can't use typeof on React.createElement since it's overloaded. Approximate createElement's signature for now and widen as needed.
|
|
18
|
+
export function withSlots<P>(
|
|
19
|
+
reactType: NativeReactType,
|
|
20
|
+
props?: (React.Attributes & P) | null,
|
|
21
|
+
...children: React.ReactNode[]
|
|
22
|
+
): ReturnType<React.FunctionComponent<P>> {
|
|
23
|
+
// if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
|
|
24
|
+
return renderSlot<P>(reactType, props, ...children);
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,11 +10,18 @@ export type {
|
|
|
10
10
|
} from './immutable-merge/Merge';
|
|
11
11
|
|
|
12
12
|
// memo-cache exports
|
|
13
|
-
export type { GetMemoValue } from './memo-cache/getMemoCache';
|
|
14
|
-
export { getMemoCache } from './memo-cache/getMemoCache';
|
|
13
|
+
export type { GetMemoValue, GetTypedMemoValue } from './memo-cache/getMemoCache';
|
|
14
|
+
export { getMemoCache, getTypedMemoCache } from './memo-cache/getMemoCache';
|
|
15
15
|
export { memoize } from './memo-cache/memoize';
|
|
16
16
|
|
|
17
17
|
// merge-props exports
|
|
18
18
|
export type { StyleProp } from './merge-props/mergeStyles.types';
|
|
19
19
|
export { mergeStyles } from './merge-props/mergeStyles';
|
|
20
20
|
export { mergeProps } from './merge-props/mergeProps';
|
|
21
|
+
|
|
22
|
+
// component pattern exports
|
|
23
|
+
export { renderSlot } from './component-patterns/renderSlot';
|
|
24
|
+
export type { SlotFn, NativeReactType } from './component-patterns/renderSlot';
|
|
25
|
+
export { withSlots } from './component-patterns/withSlots';
|
|
26
|
+
export { stagedComponent } from './component-patterns/stagedComponent';
|
|
27
|
+
export type { FinalRender, StagedRender, ComposableFunction } from './component-patterns/stagedComponent';
|
|
@@ -1,54 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
/** signature for the object/function key values, used for memoization */
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
3
|
+
export type MemoObjectKey = object | Function;
|
|
4
|
+
|
|
5
|
+
export type CacheEntry<T = unknown> = {
|
|
2
6
|
/** stores the cached value if any */
|
|
3
7
|
value?: T;
|
|
4
8
|
|
|
5
9
|
/** entry used for undefined and null values, these both collapse to the same type */
|
|
6
|
-
empty?: CacheEntry<
|
|
10
|
+
empty?: CacheEntry<T>;
|
|
7
11
|
|
|
8
12
|
/** entry used for the case where the array of args is null or length 0 */
|
|
9
|
-
noargs?: CacheEntry<
|
|
13
|
+
noargs?: CacheEntry<T>;
|
|
10
14
|
|
|
11
15
|
/** all remaining non-object types are keyed as strings for lookups */
|
|
12
|
-
str?: { [key: string]: CacheEntry<
|
|
16
|
+
str?: { [key: string]: CacheEntry<T> };
|
|
13
17
|
|
|
14
18
|
/** object types are keyed in a weak map on object identity */
|
|
15
|
-
obj?: WeakMap<
|
|
19
|
+
obj?: WeakMap<MemoObjectKey, CacheEntry<T>>;
|
|
16
20
|
};
|
|
17
21
|
|
|
18
|
-
/**
|
|
19
|
-
* just wraps the common entry.foo = entry.foo || {} pattern
|
|
20
|
-
* @param entry - entry to ensure a key value for
|
|
21
|
-
* @param key - which key of that entry to ensure the value for
|
|
22
|
-
*/
|
|
23
|
-
function ensureAndReturn(entry: CacheEntry<any>, key: keyof CacheEntry<any>): CacheEntry<any> | { [key: string]: CacheEntry<any> } {
|
|
24
|
-
if ((key as string) === '__proto__' || (key as string) === 'constructor' || (key as string) === 'prototype') {
|
|
25
|
-
throw new Error('Invalid key');
|
|
26
|
-
}
|
|
27
|
-
return (entry[key] = entry[key] || {});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
22
|
/**
|
|
31
23
|
* Step one level deeper in the cache, based on the key value from the current location
|
|
32
24
|
*
|
|
33
25
|
* @param entry - base entry to work from
|
|
34
26
|
* @param val - value to use as the key for progressing to the next level of the cache
|
|
35
27
|
*/
|
|
36
|
-
function jumpToCacheEntry(entry: CacheEntry
|
|
28
|
+
function jumpToCacheEntry(entry: CacheEntry, val: any): CacheEntry {
|
|
37
29
|
if (val === undefined || val === null) {
|
|
38
30
|
// undefined or null just routes directly to the empty object. This avoids the issues of string collisions with 'null' or 'undefined'
|
|
39
31
|
// when using the string key map, it also avoids creating the WeakMap (since null is technically typoef object), particularly in cases
|
|
40
32
|
// where null is just being set on non-object types.
|
|
41
|
-
return
|
|
33
|
+
return (entry.empty ??= {});
|
|
42
34
|
}
|
|
43
35
|
if (typeof val === 'object' || typeof val === 'function') {
|
|
44
36
|
// objects and functions will be treated as key values in a WeakMap
|
|
45
|
-
const byObj = (entry.obj
|
|
37
|
+
const byObj = (entry.obj ??= new WeakMap<MemoObjectKey, CacheEntry>());
|
|
46
38
|
return byObj.get(val) || byObj.set(val, {}).get(val);
|
|
47
39
|
}
|
|
48
40
|
// otherwise convert everything to a string and store it in the str object (using it as a map)
|
|
49
41
|
const key = val + '';
|
|
50
|
-
const byString =
|
|
51
|
-
return (byString[key]
|
|
42
|
+
const byString = (entry.str ??= {});
|
|
43
|
+
return (byString[key] ??= {});
|
|
52
44
|
}
|
|
53
45
|
|
|
54
46
|
/**
|
|
@@ -57,11 +49,11 @@ function jumpToCacheEntry(entry: CacheEntry<any>, val: any): CacheEntry<any> {
|
|
|
57
49
|
* @param entry - entry to use as the base of the cache walk
|
|
58
50
|
* @param args - array of arguments to use to progress deeper into the cache
|
|
59
51
|
*/
|
|
60
|
-
export function getCacheEntry
|
|
52
|
+
export function getCacheEntry(entry: CacheEntry, args: unknown[]): CacheEntry {
|
|
61
53
|
// in the case where the args array exists and is > 0 length:
|
|
62
54
|
// - walk the cache from entry, like a linked list, jumping to the next entry by key, building it up as you go
|
|
63
55
|
// - otherwise if there are no args just use the noargs branch
|
|
64
56
|
return args && args.length > 0
|
|
65
|
-
? (args.reduce((previous: CacheEntry
|
|
66
|
-
:
|
|
57
|
+
? (args.reduce((previous: CacheEntry, arg: unknown) => jumpToCacheEntry(previous, arg), entry) as CacheEntry)
|
|
58
|
+
: (entry.noargs ??= {});
|
|
67
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getMemoCache } from './getMemoCache';
|
|
1
|
+
import { getMemoCache, getTypedMemoCache } from './getMemoCache';
|
|
2
2
|
|
|
3
3
|
interface TestObj {
|
|
4
4
|
id: number;
|
|
@@ -38,7 +38,7 @@ describe('getMemoCache unit tests', () => {
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
test('memoValue executes function', () => {
|
|
41
|
-
const memoValue =
|
|
41
|
+
const memoValue = getTypedMemoCache<TestObj>();
|
|
42
42
|
const fn = getObjFactory();
|
|
43
43
|
const v1 = fn();
|
|
44
44
|
const [v2] = memoValue(fn, ['bar', 'baz']);
|