@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
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,37 @@
|
|
|
2
2
|
"name": "@fluentui-react-native/framework-base",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "Wed,
|
|
5
|
+
"date": "Wed, 23 Jul 2025 00:18:14 GMT",
|
|
6
|
+
"version": "0.1.3",
|
|
7
|
+
"tag": "@fluentui-react-native/framework-base_v0.1.3",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "jasonmo@microsoft.com",
|
|
12
|
+
"package": "@fluentui-react-native/framework-base",
|
|
13
|
+
"commit": "dd4d507b4ebca7f13757f54cb36f762a3a50d9cc",
|
|
14
|
+
"comment": "fix types in memo-cache as well as a codescan security issue"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Tue, 22 Jul 2025 19:06:23 GMT",
|
|
21
|
+
"version": "0.1.2",
|
|
22
|
+
"tag": "@fluentui-react-native/framework-base_v0.1.2",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "jasonmo@microsoft.com",
|
|
27
|
+
"package": "@fluentui-react-native/framework-base",
|
|
28
|
+
"commit": "21e536f6875cb6fb9c33b439f0eafe1d4debc7a4",
|
|
29
|
+
"comment": "centralize jsx rendering functionality in framework-base"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Wed, 16 Jul 2025 20:06:45 GMT",
|
|
6
36
|
"version": "0.1.1",
|
|
7
37
|
"tag": "@fluentui-react-native/framework-base_v0.1.1",
|
|
8
38
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
# Change Log - @fluentui-react-native/framework-base
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on Wed,
|
|
3
|
+
<!-- This log was last generated on Wed, 23 Jul 2025 00:18:14 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.1.3
|
|
8
|
+
|
|
9
|
+
Wed, 23 Jul 2025 00:18:14 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- fix types in memo-cache as well as a codescan security issue (jasonmo@microsoft.com)
|
|
14
|
+
|
|
15
|
+
## 0.1.2
|
|
16
|
+
|
|
17
|
+
Tue, 22 Jul 2025 19:06:23 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- centralize jsx rendering functionality in framework-base (jasonmo@microsoft.com)
|
|
22
|
+
|
|
7
23
|
## 0.1.1
|
|
8
24
|
|
|
9
|
-
Wed, 16 Jul 2025 20:
|
|
25
|
+
Wed, 16 Jul 2025 20:06:45 GMT
|
|
10
26
|
|
|
11
27
|
### Patches
|
|
12
28
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Component slots have a marker which allows the slot render handler to know which ones are safe to call as a function.
|
|
4
|
+
*/
|
|
5
|
+
export type SlotFn<TProps> = React.FunctionComponent<TProps> & {
|
|
6
|
+
_canCompose?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The standard element type inputs for react and react-native. This might be View or Button, or it might be 'div' in web. Effectively
|
|
10
|
+
* it is what react accepts for React.createElement
|
|
11
|
+
*/
|
|
12
|
+
export type NativeReactType = React.ElementType<any> | string;
|
|
13
|
+
/**
|
|
14
|
+
* Renders a slot
|
|
15
|
+
*
|
|
16
|
+
* @param slot - native react type or slot function to render
|
|
17
|
+
* @param extraProps - additional props to mixin
|
|
18
|
+
* @param children - the children to pass down to the slot
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderSlot<TProps>(slot: NativeReactType | SlotFn<TProps>, extraProps: TProps, ...children: React.ReactNode[]): React.ReactElement<any, any>;
|
|
21
|
+
//# sourceMappingURL=renderSlot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderSlot.d.ts","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,gCAI5H"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Renders a slot
|
|
4
|
+
*
|
|
5
|
+
* @param slot - native react type or slot function to render
|
|
6
|
+
* @param extraProps - additional props to mixin
|
|
7
|
+
* @param children - the children to pass down to the slot
|
|
8
|
+
*/
|
|
9
|
+
export function renderSlot(slot, extraProps, ...children) {
|
|
10
|
+
return typeof slot === 'function' && slot._canCompose
|
|
11
|
+
? slot(extraProps, ...children)
|
|
12
|
+
: React.createElement(slot, extraProps, ...children);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=renderSlot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderSlot.js","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAe/B;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAS,IAAsC,EAAE,UAAkB,EAAE,GAAG,QAA2B;IAC3H,OAAO,OAAO,IAAI,KAAK,UAAU,IAAK,IAAuB,CAAC,WAAW;QACvE,CAAC,CAAE,IAAuB,CAAC,UAAU,EAAE,GAAG,QAAQ,CAAC;QACnD,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The final rendering of the props in a staged render. This is the function component signature that matches that of
|
|
4
|
+
* React.createElement, children (if present) will be part of the variable args at the end.
|
|
5
|
+
*/
|
|
6
|
+
export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => JSX.Element | null;
|
|
7
|
+
/**
|
|
8
|
+
* This is a pattern of rendering where a functional component can be executed in two stages rather than in a single pass.
|
|
9
|
+
*
|
|
10
|
+
* The pattern looks like:
|
|
11
|
+
* (props) => {
|
|
12
|
+
* // handle props
|
|
13
|
+
* // call hooks, remember these can't be conditional
|
|
14
|
+
* // build styles and props to pass to child components
|
|
15
|
+
*
|
|
16
|
+
* return (additionalProps, ...children) => {
|
|
17
|
+
* // return the actual element tree, this includes conditional branching or rendering
|
|
18
|
+
* // mixin additional props, props which require logic should be required in phase 1.
|
|
19
|
+
*
|
|
20
|
+
* // NOTE: This is where children will show up
|
|
21
|
+
* };
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export type StagedRender<TProps> = (props: TProps, ...args: any[]) => FinalRender<TProps>;
|
|
25
|
+
/**
|
|
26
|
+
* A composable function may have a two stage render function as an attached property. This allows the function to work
|
|
27
|
+
* in all the standard react flows, but allows for pulling out the staged render when components understand it.
|
|
28
|
+
*/
|
|
29
|
+
export type ComposableFunction<TProps> = React.FunctionComponent<TProps> & {
|
|
30
|
+
_staged?: StagedRender<TProps>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Take a staged render function and make a real component out of it
|
|
34
|
+
*
|
|
35
|
+
* @param staged - staged render function to wrap into a staged component
|
|
36
|
+
* @param memo - optional flag to enable wrapping the created component in a React.memo HOC
|
|
37
|
+
*/
|
|
38
|
+
export declare function stagedComponent<TProps>(staged: StagedRender<TProps>, memo?: boolean): ComposableFunction<TProps>;
|
|
39
|
+
//# sourceMappingURL=stagedComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stagedComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;AAExG;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,YAAY,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC;AAE1F;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAM9G;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAQhH"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
function asArray(val) {
|
|
3
|
+
return Array.isArray(val) ? val : [val];
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Take a staged render function and make a real component out of it
|
|
7
|
+
*
|
|
8
|
+
* @param staged - staged render function to wrap into a staged component
|
|
9
|
+
* @param memo - optional flag to enable wrapping the created component in a React.memo HOC
|
|
10
|
+
*/
|
|
11
|
+
export function stagedComponent(staged, memo) {
|
|
12
|
+
const component = (props) => {
|
|
13
|
+
const { children, ...rest } = props;
|
|
14
|
+
return staged(rest)({}, asArray(children));
|
|
15
|
+
};
|
|
16
|
+
const stagedComponent = memo ? React.memo(component) : component;
|
|
17
|
+
Object.assign(stagedComponent, { _staged: staged });
|
|
18
|
+
return stagedComponent;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=stagedComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stagedComponent.js","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkC/B,SAAS,OAAO,CAAI,GAAY;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAS,MAA4B,EAAE,IAAc;IAClF,MAAM,SAAS,GAAG,CAAC,KAAsC,EAAE,EAAE;QAC3D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QACpC,OAAO,MAAM,CAAC,IAAc,CAAC,CAAC,EAAqC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC;IACF,MAAM,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,OAAO,eAA6C,CAAC;AACvD,CAAC"}
|
|
@@ -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,19 @@
|
|
|
1
|
+
import { renderSlot } 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
|
+
// Can't use typeof on React.createElement since it's overloaded. Approximate createElement's signature for now and widen as needed.
|
|
15
|
+
export function withSlots(reactType, props, ...children) {
|
|
16
|
+
// if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
|
|
17
|
+
return renderSlot(reactType, props, ...children);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=withSlots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withSlots.js","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;GAWG;AAEH,oIAAoI;AACpI,MAAM,UAAU,SAAS,CACvB,SAA0B,EAC1B,KAAqC,EACrC,GAAG,QAA2B;IAE9B,0HAA0H;IAC1H,OAAO,UAAU,CAAI,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;AACtD,CAAC"}
|
package/lib/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
|
package/lib/index.d.ts.map
CHANGED
|
@@ -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/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// immutable-merge exports
|
|
2
2
|
export { immutableMerge, immutableMergeCore, processImmutable, filterToObjects } from './immutable-merge/Merge';
|
|
3
|
-
export { getMemoCache } from './memo-cache/getMemoCache';
|
|
3
|
+
export { getMemoCache, getTypedMemoCache } from './memo-cache/getMemoCache';
|
|
4
4
|
export { memoize } from './memo-cache/memoize';
|
|
5
5
|
export { mergeStyles } from './merge-props/mergeStyles';
|
|
6
6
|
export { mergeProps } from './merge-props/mergeProps';
|
|
7
|
+
// component pattern exports
|
|
8
|
+
export { renderSlot } from './component-patterns/renderSlot';
|
|
9
|
+
export { withSlots } from './component-patterns/withSlots';
|
|
10
|
+
export { stagedComponent } from './component-patterns/stagedComponent';
|
|
7
11
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAYhH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAYhH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI/C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,4BAA4B;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC"}
|
|
@@ -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,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* just wraps the common entry.foo = entry.foo || {} pattern
|
|
3
|
-
* @param entry - entry to ensure a key value for
|
|
4
|
-
* @param key - which key of that entry to ensure the value for
|
|
5
|
-
*/
|
|
6
|
-
function ensureAndReturn(entry, key) {
|
|
7
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
8
|
-
throw new Error('Invalid key');
|
|
9
|
-
}
|
|
10
|
-
return (entry[key] = entry[key] || {});
|
|
11
|
-
}
|
|
12
1
|
/**
|
|
13
2
|
* Step one level deeper in the cache, based on the key value from the current location
|
|
14
3
|
*
|
|
@@ -20,17 +9,17 @@ function jumpToCacheEntry(entry, val) {
|
|
|
20
9
|
// undefined or null just routes directly to the empty object. This avoids the issues of string collisions with 'null' or 'undefined'
|
|
21
10
|
// when using the string key map, it also avoids creating the WeakMap (since null is technically typoef object), particularly in cases
|
|
22
11
|
// where null is just being set on non-object types.
|
|
23
|
-
return
|
|
12
|
+
return (entry.empty ??= {});
|
|
24
13
|
}
|
|
25
14
|
if (typeof val === 'object' || typeof val === 'function') {
|
|
26
15
|
// objects and functions will be treated as key values in a WeakMap
|
|
27
|
-
const byObj = (entry.obj
|
|
16
|
+
const byObj = (entry.obj ??= new WeakMap());
|
|
28
17
|
return byObj.get(val) || byObj.set(val, {}).get(val);
|
|
29
18
|
}
|
|
30
19
|
// otherwise convert everything to a string and store it in the str object (using it as a map)
|
|
31
20
|
const key = val + '';
|
|
32
|
-
const byString =
|
|
33
|
-
return (byString[key]
|
|
21
|
+
const byString = (entry.str ??= {});
|
|
22
|
+
return (byString[key] ??= {});
|
|
34
23
|
}
|
|
35
24
|
/**
|
|
36
25
|
* Given a base entry, either traverse or build the cache tree that matches the provided args
|
|
@@ -44,6 +33,6 @@ export function getCacheEntry(entry, args) {
|
|
|
44
33
|
// - otherwise if there are no args just use the noargs branch
|
|
45
34
|
return args && args.length > 0
|
|
46
35
|
? args.reduce((previous, arg) => jumpToCacheEntry(previous, arg), entry)
|
|
47
|
-
:
|
|
36
|
+
: (entry.noargs ??= {});
|
|
48
37
|
}
|
|
49
38
|
//# 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,MAAM,UAAU,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"}
|
|
@@ -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"}
|
|
@@ -11,7 +11,7 @@ const _baseEntry = {};
|
|
|
11
11
|
function getMemoValueWorker(entry, factory, keys) {
|
|
12
12
|
const foundEntry = getCacheEntry(entry, keys);
|
|
13
13
|
// check the key being set, not the value to disambiguate an undefined factory result/value from never having run the factory
|
|
14
|
-
if (!
|
|
14
|
+
if (!Object.prototype.hasOwnProperty.call(foundEntry, 'value')) {
|
|
15
15
|
foundEntry.value = typeof factory === 'function' ? factory() : factory;
|
|
16
16
|
}
|
|
17
17
|
return [foundEntry.value, (fact, args) => getMemoValueWorker(foundEntry, fact, args)];
|
|
@@ -26,4 +26,14 @@ export function getMemoCache(globalKey) {
|
|
|
26
26
|
const entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
|
|
27
27
|
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Get a typed memo cache instance, this can either be completely self-contained or associated with a global key
|
|
31
|
+
*
|
|
32
|
+
* @param globalKey - optional object reference to use as a key for this cache. If specified it can be used
|
|
33
|
+
* to retrieve the same cache from the global call. If not specified the returned cache will be completely isolated.
|
|
34
|
+
*/
|
|
35
|
+
export function getTypedMemoCache(globalKey) {
|
|
36
|
+
const entry = globalKey ? getCacheEntry(_baseEntry, [globalKey]) : {};
|
|
37
|
+
return (fact, args) => getMemoValueWorker(entry, fact, args);
|
|
38
|
+
}
|
|
29
39
|
//# sourceMappingURL=getMemoCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"getMemoCache.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAYhD,oEAAoE;AACpE,MAAM,UAAU,GAAe,EAAE,CAAC;AAElC;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAI,KAAiB,EAAE,OAA4B,EAAE,IAAe;IAC7F,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9C,6HAA6H;IAC7H,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE;QAC9D,UAAU,CAAC,KAAK,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAE,OAA2B,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;KAC7F;IACD,OAAO,CAAC,UAAU,CAAC,KAAU,EAAE,CAAI,IAAyB,EAAE,IAAe,EAAE,EAAE,CAAC,kBAAkB,CAAI,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACnI,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,SAAkB;IAC7C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAI,SAAkB;IACrD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getMemoCache } from './getMemoCache';
|
|
1
|
+
import { getMemoCache, getTypedMemoCache } from './getMemoCache';
|
|
2
2
|
function getObjFactory() {
|
|
3
3
|
const obj = { id: 0 };
|
|
4
4
|
return () => ({
|
|
@@ -28,7 +28,7 @@ describe('getMemoCache unit tests', () => {
|
|
|
28
28
|
expect(val).toBe(obj);
|
|
29
29
|
});
|
|
30
30
|
test('memoValue executes function', () => {
|
|
31
|
-
const memoValue =
|
|
31
|
+
const memoValue = getTypedMemoCache();
|
|
32
32
|
const fn = getObjFactory();
|
|
33
33
|
const v1 = fn();
|
|
34
34
|
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,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"getMemoCache.test.js","sourceRoot":"","sources":["../../src/memo-cache/getMemoCache.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;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,YAAY,EAAE,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,YAAY,EAAE,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,KAA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appings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,MAAM,UAAU,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"memoize.js","sourceRoot":"","sources":["../../src/memo-cache/memoize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,sEAAsE;AACtE,MAAM,UAAU,OAAO,CAAqB,EAAK;IAC/C,6DAA6D;IAC7D,MAAM,KAAK,GAAG,YAAY,EAAE,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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Component slots have a marker which allows the slot render handler to know which ones are safe to call as a function.
|
|
4
|
+
*/
|
|
5
|
+
export type SlotFn<TProps> = React.FunctionComponent<TProps> & {
|
|
6
|
+
_canCompose?: boolean;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The standard element type inputs for react and react-native. This might be View or Button, or it might be 'div' in web. Effectively
|
|
10
|
+
* it is what react accepts for React.createElement
|
|
11
|
+
*/
|
|
12
|
+
export type NativeReactType = React.ElementType<any> | string;
|
|
13
|
+
/**
|
|
14
|
+
* Renders a slot
|
|
15
|
+
*
|
|
16
|
+
* @param slot - native react type or slot function to render
|
|
17
|
+
* @param extraProps - additional props to mixin
|
|
18
|
+
* @param children - the children to pass down to the slot
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderSlot<TProps>(slot: NativeReactType | SlotFn<TProps>, extraProps: TProps, ...children: React.ReactNode[]): React.ReactElement<any, any>;
|
|
21
|
+
//# sourceMappingURL=renderSlot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderSlot.d.ts","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAC7D,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,gCAI5H"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderSlot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const React = tslib_1.__importStar(require("react"));
|
|
6
|
+
/**
|
|
7
|
+
* Renders a slot
|
|
8
|
+
*
|
|
9
|
+
* @param slot - native react type or slot function to render
|
|
10
|
+
* @param extraProps - additional props to mixin
|
|
11
|
+
* @param children - the children to pass down to the slot
|
|
12
|
+
*/
|
|
13
|
+
function renderSlot(slot, extraProps, ...children) {
|
|
14
|
+
return typeof slot === 'function' && slot._canCompose
|
|
15
|
+
? slot(extraProps, ...children)
|
|
16
|
+
: React.createElement(slot, extraProps, ...children);
|
|
17
|
+
}
|
|
18
|
+
exports.renderSlot = renderSlot;
|
|
19
|
+
//# sourceMappingURL=renderSlot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderSlot.js","sourceRoot":"","sources":["../../src/component-patterns/renderSlot.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAe/B;;;;;;GAMG;AACH,SAAgB,UAAU,CAAS,IAAsC,EAAE,UAAkB,EAAE,GAAG,QAA2B;IAC3H,OAAO,OAAO,IAAI,KAAK,UAAU,IAAK,IAAuB,CAAC,WAAW;QACvE,CAAC,CAAE,IAAuB,CAAC,UAAU,EAAE,GAAG,QAAQ,CAAC;QACnD,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC,CAAC;AACzD,CAAC;AAJD,gCAIC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The final rendering of the props in a staged render. This is the function component signature that matches that of
|
|
4
|
+
* React.createElement, children (if present) will be part of the variable args at the end.
|
|
5
|
+
*/
|
|
6
|
+
export type FinalRender<TProps> = (props: TProps, ...children: React.ReactNode[]) => JSX.Element | null;
|
|
7
|
+
/**
|
|
8
|
+
* This is a pattern of rendering where a functional component can be executed in two stages rather than in a single pass.
|
|
9
|
+
*
|
|
10
|
+
* The pattern looks like:
|
|
11
|
+
* (props) => {
|
|
12
|
+
* // handle props
|
|
13
|
+
* // call hooks, remember these can't be conditional
|
|
14
|
+
* // build styles and props to pass to child components
|
|
15
|
+
*
|
|
16
|
+
* return (additionalProps, ...children) => {
|
|
17
|
+
* // return the actual element tree, this includes conditional branching or rendering
|
|
18
|
+
* // mixin additional props, props which require logic should be required in phase 1.
|
|
19
|
+
*
|
|
20
|
+
* // NOTE: This is where children will show up
|
|
21
|
+
* };
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export type StagedRender<TProps> = (props: TProps, ...args: any[]) => FinalRender<TProps>;
|
|
25
|
+
/**
|
|
26
|
+
* A composable function may have a two stage render function as an attached property. This allows the function to work
|
|
27
|
+
* in all the standard react flows, but allows for pulling out the staged render when components understand it.
|
|
28
|
+
*/
|
|
29
|
+
export type ComposableFunction<TProps> = React.FunctionComponent<TProps> & {
|
|
30
|
+
_staged?: StagedRender<TProps>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Take a staged render function and make a real component out of it
|
|
34
|
+
*
|
|
35
|
+
* @param staged - staged render function to wrap into a staged component
|
|
36
|
+
* @param memo - optional flag to enable wrapping the created component in a React.memo HOC
|
|
37
|
+
*/
|
|
38
|
+
export declare function stagedComponent<TProps>(staged: StagedRender<TProps>, memo?: boolean): ComposableFunction<TProps>;
|
|
39
|
+
//# sourceMappingURL=stagedComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stagedComponent.d.ts","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;AAExG;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,YAAY,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,WAAW,CAAC,MAAM,CAAC,CAAC;AAE1F;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAM9G;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAQhH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stagedComponent = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const React = tslib_1.__importStar(require("react"));
|
|
6
|
+
function asArray(val) {
|
|
7
|
+
return Array.isArray(val) ? val : [val];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Take a staged render function and make a real component out of it
|
|
11
|
+
*
|
|
12
|
+
* @param staged - staged render function to wrap into a staged component
|
|
13
|
+
* @param memo - optional flag to enable wrapping the created component in a React.memo HOC
|
|
14
|
+
*/
|
|
15
|
+
function stagedComponent(staged, memo) {
|
|
16
|
+
const component = (props) => {
|
|
17
|
+
const { children, ...rest } = props;
|
|
18
|
+
return staged(rest)({}, asArray(children));
|
|
19
|
+
};
|
|
20
|
+
const stagedComponent = memo ? React.memo(component) : component;
|
|
21
|
+
Object.assign(stagedComponent, { _staged: staged });
|
|
22
|
+
return stagedComponent;
|
|
23
|
+
}
|
|
24
|
+
exports.stagedComponent = stagedComponent;
|
|
25
|
+
//# sourceMappingURL=stagedComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stagedComponent.js","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAkC/B,SAAS,OAAO,CAAI,GAAY;IAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAS,MAA4B,EAAE,IAAc;IAClF,MAAM,SAAS,GAAG,CAAC,KAAsC,EAAE,EAAE;QAC3D,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;QACpC,OAAO,MAAM,CAAC,IAAc,CAAC,CAAC,EAAqC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC;IACF,MAAM,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACjE,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACpD,OAAO,eAA6C,CAAC;AACvD,CAAC;AARD,0CAQC"}
|