@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,38 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxRuntime classic
|
|
3
|
-
* @jsx withSlots
|
|
4
|
-
*/
|
|
5
1
|
import * as React from 'react';
|
|
6
|
-
import { withSlots } from './withSlots';
|
|
7
2
|
function asArray(val) {
|
|
8
|
-
|
|
3
|
+
return Array.isArray(val) ? val : [val];
|
|
9
4
|
}
|
|
10
5
|
/**
|
|
11
6
|
* Take a staged render function and make a real component out of it
|
|
12
7
|
*
|
|
13
8
|
* @param staged - staged render function to wrap into a staged component
|
|
14
9
|
* @param memo - optional flag to enable wrapping the created component in a React.memo HOC
|
|
10
|
+
* @deprecated Use phasedComponent from phasedComponent.ts instead
|
|
15
11
|
*/
|
|
16
12
|
export function stagedComponent(staged, memo) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Take a two stage render function and make a real component out of it, attaching the staged render function
|
|
27
|
-
* so it can be split if used in that manner.
|
|
28
|
-
* @param staged - two stage render function to wrap into a staged component
|
|
29
|
-
*/
|
|
30
|
-
export function twoStageComponent(staged) {
|
|
31
|
-
return Object.assign((props) => {
|
|
32
|
-
const { children, ...outerProps } = props;
|
|
33
|
-
const innerProps = { children };
|
|
34
|
-
const Inner = staged(outerProps);
|
|
35
|
-
return withSlots(Inner, { ...innerProps });
|
|
36
|
-
}, { _twoStageRender: staged });
|
|
13
|
+
const component = (props) => {
|
|
14
|
+
const { children, ...rest } = props;
|
|
15
|
+
return staged(rest)({}, asArray(children));
|
|
16
|
+
};
|
|
17
|
+
const stagedComponent = memo ? React.memo(component) : component;
|
|
18
|
+
Object.assign(stagedComponent, { _staged: staged });
|
|
19
|
+
return stagedComponent;
|
|
37
20
|
}
|
|
38
|
-
//# sourceMappingURL=stagedComponent.js.map
|
|
21
|
+
//# sourceMappingURL=stagedComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stagedComponent.js","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.
|
|
1
|
+
{"version":3,"file":"stagedComponent.js","sourceRoot":"","sources":["../../src/component-patterns/stagedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,SAAS,OAAO,CAAI,GAAY,EAAO;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAAA,CACzC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAS,MAA4B,EAAE,IAAc,EAA8B;IAChH,MAAM,SAAS,GAAG,CAAC,KAAsC,EAAE,EAAE,CAAC;QAC5D,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;IAAA,CACzF,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;AAAA,CACtD"}
|
|
@@ -11,5 +11,9 @@ import type React from 'react';
|
|
|
11
11
|
*
|
|
12
12
|
* See React.createElement
|
|
13
13
|
*/
|
|
14
|
-
export declare function withSlots(
|
|
15
|
-
|
|
14
|
+
export declare function withSlots(
|
|
15
|
+
reactType: Parameters<typeof React.createElement>[0],
|
|
16
|
+
props?: unknown,
|
|
17
|
+
...children: React.ReactNode[]
|
|
18
|
+
): import('..').FurnJSX.Element;
|
|
19
|
+
//# sourceMappingURL=withSlots.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSlots.d.ts","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;;;;;;;;;;;GAWG;AAGH,wBAAgB,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"withSlots.d.ts","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B;;;;;;;;;;;GAWG;AAGH,wBAAgB,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,GAAG,QAAQ,EAAE,KAAK,CAAC,SAAS,EAAE,gCAG9H"}
|
|
@@ -13,7 +13,7 @@ import { renderForClassicRuntime } from './render';
|
|
|
13
13
|
*/
|
|
14
14
|
// Can't use typeof on React.createElement since it's overloaded. Approximate createElement's signature for now and widen as needed.
|
|
15
15
|
export function withSlots(reactType, props, ...children) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// if it is a non-string type with _canCompose set just call the function directly, otherwise call createElement as normal
|
|
17
|
+
return renderForClassicRuntime(reactType, props, ...children);
|
|
18
18
|
}
|
|
19
|
-
//# sourceMappingURL=withSlots.js.map
|
|
19
|
+
//# sourceMappingURL=withSlots.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withSlots.js","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;;;;;;;GAWG;AAEH,oIAAoI;AACpI,MAAM,UAAU,SAAS,CAAC,SAAoD,EAAE,KAAe,EAAE,GAAG,QAA2B;
|
|
1
|
+
{"version":3,"file":"withSlots.js","sourceRoot":"","sources":["../../src/component-patterns/withSlots.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;;;;;;;GAWG;AAEH,oIAAoI;AACpI,MAAM,UAAU,SAAS,CAAC,SAAoD,EAAE,KAAe,EAAE,GAAG,QAA2B,EAAE;IAC/H,0HAA0H;IAC1H,OAAO,uBAAuB,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,CAAC;AAAA,CAC/D"}
|
|
@@ -41,7 +41,7 @@ export type ExpandedTypeof = TypeofResult | 'array' | 'null';
|
|
|
41
41
|
* - [key: string]: matches anything by name
|
|
42
42
|
*/
|
|
43
43
|
export interface MergeOptions {
|
|
44
|
-
|
|
44
|
+
[objectTypeOrKeyName: string]: RecursionOption | RecursionHandler | MergeOptions;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Filter a set of unknown values to only include those that extend ObjectBase
|
|
@@ -62,7 +62,10 @@ export declare function immutableMerge<T extends ObjectBase>(...objs: (T | undef
|
|
|
62
62
|
* @param options - configuration options for the merge, this dictates what keys will be handled in what way
|
|
63
63
|
* @param objs - set of objects to merge together
|
|
64
64
|
*/
|
|
65
|
-
export declare function immutableMergeCore<T extends ObjectBase>(
|
|
65
|
+
export declare function immutableMergeCore<T extends ObjectBase>(
|
|
66
|
+
options: RecursionOption | MergeOptions,
|
|
67
|
+
...objs: (T | undefined)[]
|
|
68
|
+
): T | undefined;
|
|
66
69
|
/**
|
|
67
70
|
* Process one or more immutable objects ensuring that handlers are called on every entry that applies. If a single object
|
|
68
71
|
* is passed in and no changes are made, that object will be returned. If updates happen from the handlers it will return the
|
|
@@ -75,4 +78,4 @@ export declare function immutableMergeCore<T extends ObjectBase>(options: Recurs
|
|
|
75
78
|
* @param objs - one or more objects to process. If multiple objects are passed they will be merged
|
|
76
79
|
*/
|
|
77
80
|
export declare function processImmutable<T extends ObjectBase>(options: MergeOptions, ...objs: (T | undefined)[]): T | undefined;
|
|
78
|
-
//# sourceMappingURL=Merge.d.ts.map
|
|
81
|
+
//# sourceMappingURL=Merge.d.ts.map
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
* built in handlers for the module
|
|
3
3
|
*/
|
|
4
4
|
const _builtinHandlers = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
appendArray: (...objs) => {
|
|
6
|
+
return [].concat(...objs);
|
|
7
|
+
},
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* This processes the various type options for merge core and turns them into a MergeConfig
|
|
11
11
|
* @param options - options passed into immutableMergeCore
|
|
12
12
|
*/
|
|
13
13
|
function normalizeOptions(options) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
return typeof options === 'boolean'
|
|
15
|
+
? [{ object: options }, options]
|
|
16
|
+
: typeof options === 'number'
|
|
17
|
+
? [{ object: options >= 0 ? options : true }, options !== 0]
|
|
18
|
+
: [options, true];
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Provide a more sensible type result that expands upon the built in typeof operator
|
|
@@ -23,41 +23,38 @@ function normalizeOptions(options) {
|
|
|
23
23
|
* @param val - value to check type
|
|
24
24
|
*/
|
|
25
25
|
function getEntityType(val) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
26
|
+
switch (typeof val) {
|
|
27
|
+
case 'object':
|
|
28
|
+
if (val === null) {
|
|
29
|
+
return 'null';
|
|
30
|
+
} else if (Array.isArray(val)) {
|
|
31
|
+
return 'array';
|
|
32
|
+
}
|
|
33
|
+
return 'object';
|
|
34
|
+
default:
|
|
35
|
+
return typeof val;
|
|
36
|
+
}
|
|
38
37
|
}
|
|
39
38
|
/** resolve custom handlers if they are applicable */
|
|
40
39
|
function resolveIfHandler(option) {
|
|
41
|
-
|
|
40
|
+
return typeof option === 'function' ? option : typeof option === 'string' ? _builtinHandlers[option] : undefined;
|
|
42
41
|
}
|
|
43
42
|
/** pass array configurations down, this allows for saying all arrays should be appended rather than replaced */
|
|
44
43
|
function getTypesMixin(config) {
|
|
45
|
-
|
|
44
|
+
return config.array ? { array: config.array } : {};
|
|
46
45
|
}
|
|
47
46
|
/** resolve the object behaviors for configuration */
|
|
48
47
|
function resolveForObject(option, mixin) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return option;
|
|
60
|
-
}
|
|
48
|
+
if (typeof option === 'boolean') {
|
|
49
|
+
// booleans won't recurse if false, otherwise recurse infinitely
|
|
50
|
+
return option ? { object: option, ...mixin } : mixin;
|
|
51
|
+
} else if (typeof option === 'number') {
|
|
52
|
+
// numbers get decremented or set to false if we've reached zero. Negative values will have been converted to boolean true
|
|
53
|
+
return option === 0 ? mixin : { object: option - 1, ...mixin };
|
|
54
|
+
} else {
|
|
55
|
+
// otherwise it is an object type so just pass the child object through
|
|
56
|
+
return option;
|
|
57
|
+
}
|
|
61
58
|
}
|
|
62
59
|
/**
|
|
63
60
|
* Figure out the handler for this property.
|
|
@@ -65,17 +62,17 @@ function resolveForObject(option, mixin) {
|
|
|
65
62
|
* in the undefined case, this key will be left as-is
|
|
66
63
|
*/
|
|
67
64
|
function getHandlerForPropertyOfType(config, propKey, propType) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
65
|
+
let result = undefined;
|
|
66
|
+
const option = config[propKey] !== undefined ? config[propKey] : config[propType] !== undefined ? config[propType] : undefined;
|
|
67
|
+
if (option !== undefined) {
|
|
68
|
+
// try to resolve the option as a handler, either function or built-in first. This is the only option that is valid for non-object types.
|
|
69
|
+
result = resolveIfHandler(option);
|
|
70
|
+
// if it is an object then resolve boolean, number or config types
|
|
71
|
+
if (result === undefined && propType === 'object') {
|
|
72
|
+
result = resolveForObject(option, getTypesMixin(config));
|
|
77
73
|
}
|
|
78
|
-
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
79
76
|
}
|
|
80
77
|
/**
|
|
81
78
|
* Assign properties of source objects to a new target object. This is just a type wrapper around Object.assign
|
|
@@ -83,7 +80,7 @@ function getHandlerForPropertyOfType(config, propKey, propType) {
|
|
|
83
80
|
* @returns the result of object assign on the objects, typed to T
|
|
84
81
|
*/
|
|
85
82
|
function assignToNewObject(...objs) {
|
|
86
|
-
|
|
83
|
+
return Object.assign({}, ...objs);
|
|
87
84
|
}
|
|
88
85
|
/**
|
|
89
86
|
* Filter a set of unknown values to only include those that extend ObjectBase
|
|
@@ -91,7 +88,7 @@ function assignToNewObject(...objs) {
|
|
|
91
88
|
* @returns the filtered set of values
|
|
92
89
|
*/
|
|
93
90
|
export function filterToObjects(values) {
|
|
94
|
-
|
|
91
|
+
return values.filter((v) => v && getEntityType(v) === 'object' && Object.getOwnPropertyNames(v).length > 0);
|
|
95
92
|
}
|
|
96
93
|
/**
|
|
97
94
|
* This will merge two or more objects together using an immutable style merge pattern. If there is only one object or
|
|
@@ -107,42 +104,41 @@ export function filterToObjects(values) {
|
|
|
107
104
|
* @param objs - an array of objects to merge together
|
|
108
105
|
*/
|
|
109
106
|
function immutableMergeWorker(mergeOptions, singleMode, ...objs) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
result[key] = updatedVal;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
// delete undefined keys from the object, otherwise there is no easy way to delete keys
|
|
137
|
-
if (!processSingle && result[key] === undefined) {
|
|
138
|
-
delete result[key];
|
|
139
|
-
}
|
|
107
|
+
const setToMerge = filterToObjects(objs);
|
|
108
|
+
const [options, mightRecurse] = normalizeOptions(mergeOptions);
|
|
109
|
+
const processSingle = singleMode && setToMerge.length === 1;
|
|
110
|
+
// there is work to do if there is more than one object to merge or if we are processing single objects
|
|
111
|
+
if (setToMerge.length > 1 || (processSingle && setToMerge.length === 1)) {
|
|
112
|
+
// now assign everything to get the normal property precedence (and merge all the keys)
|
|
113
|
+
let result = processSingle ? undefined : assignToNewObject(...setToMerge);
|
|
114
|
+
const processSet = result || setToMerge[0];
|
|
115
|
+
for (const key in processSet) {
|
|
116
|
+
if (processSet.hasOwnProperty(key)) {
|
|
117
|
+
// only process if there is potential work to do
|
|
118
|
+
if (mightRecurse) {
|
|
119
|
+
const originalVal = processSet[key];
|
|
120
|
+
const entityType = getEntityType(originalVal);
|
|
121
|
+
const handler = getHandlerForPropertyOfType(options, key, entityType);
|
|
122
|
+
if (handler !== undefined) {
|
|
123
|
+
const values = setToMerge.map((set) => set[key]).filter((v) => v !== undefined);
|
|
124
|
+
const updatedVal =
|
|
125
|
+
typeof handler === 'function' ? handler(...values) : immutableMergeWorker(handler, singleMode, ...filterToObjects(values));
|
|
126
|
+
if (updatedVal !== originalVal) {
|
|
127
|
+
result = result || assignToNewObject(...setToMerge);
|
|
128
|
+
result[key] = updatedVal;
|
|
140
129
|
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// delete undefined keys from the object, otherwise there is no easy way to delete keys
|
|
133
|
+
if (!processSingle && result[key] === undefined) {
|
|
134
|
+
delete result[key];
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
return result || processSet;
|
|
136
|
+
}
|
|
144
137
|
}
|
|
145
|
-
return
|
|
138
|
+
// in the single processing case return the original if nothing changed, otherwise return result
|
|
139
|
+
return result || processSet;
|
|
140
|
+
}
|
|
141
|
+
return setToMerge.length > 0 ? setToMerge[0] : undefined;
|
|
146
142
|
}
|
|
147
143
|
/**
|
|
148
144
|
* Recursively immutable merge sets of objects infinitely deep. This behaves like a standard deep merge with arrays replacing
|
|
@@ -151,7 +147,7 @@ function immutableMergeWorker(mergeOptions, singleMode, ...objs) {
|
|
|
151
147
|
* @param objs - variable input array of typed objects to merge
|
|
152
148
|
*/
|
|
153
149
|
export function immutableMerge(...objs) {
|
|
154
|
-
|
|
150
|
+
return immutableMergeWorker(true, false, ...objs);
|
|
155
151
|
}
|
|
156
152
|
/**
|
|
157
153
|
* Version of immutable merge that can be configured to behave in a variety of manners. See the documentation for details.
|
|
@@ -160,7 +156,7 @@ export function immutableMerge(...objs) {
|
|
|
160
156
|
* @param objs - set of objects to merge together
|
|
161
157
|
*/
|
|
162
158
|
export function immutableMergeCore(options, ...objs) {
|
|
163
|
-
|
|
159
|
+
return immutableMergeWorker(options, false, ...objs);
|
|
164
160
|
}
|
|
165
161
|
/**
|
|
166
162
|
* Process one or more immutable objects ensuring that handlers are called on every entry that applies. If a single object
|
|
@@ -174,6 +170,6 @@ export function immutableMergeCore(options, ...objs) {
|
|
|
174
170
|
* @param objs - one or more objects to process. If multiple objects are passed they will be merged
|
|
175
171
|
*/
|
|
176
172
|
export function processImmutable(options, ...objs) {
|
|
177
|
-
|
|
173
|
+
return immutableMergeWorker(options, true, ...objs);
|
|
178
174
|
}
|
|
179
|
-
//# sourceMappingURL=Merge.js.map
|
|
175
|
+
//# sourceMappingURL=Merge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Merge.js","sourceRoot":"","sources":["../../src/immutable-merge/Merge.ts"],"names":[],"mappings":"AAqDA;;GAEG;AACH,MAAM,gBAAgB,GAAgE;IACpF,WAAW,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"Merge.js","sourceRoot":"","sources":["../../src/immutable-merge/Merge.ts"],"names":[],"mappings":"AAqDA;;GAEG;AACH,MAAM,gBAAgB,GAAgE;IACpF,WAAW,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAAA,CAC3B;CACF,CAAC;AAEF;;;GAGG;AACH,SAAS,gBAAgB,CAAC,OAAuC,EAA2B;IAC1F,OAAO,OAAO,OAAO,KAAK,SAAS;QACjC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC;QAChC,CAAC,CAAC,OAAO,OAAO,KAAK,QAAQ;YAC7B,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,OAAO,KAAK,CAAC,CAAC;YAC5D,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAAA,CACrB;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,GAAY,EAAkB;IACnD,QAAQ,OAAO,GAAG,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBACjB,OAAO,MAAM,CAAC;YAChB,CAAC;iBAAM,IAAI,KAAK,CAAC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