lodash-es#merge TypeScript Examples
The following examples show how to use
lodash-es#merge.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: animation.ts From LogicFlow with Apache License 2.0 | 6 votes |
updateAnimation = (
config: boolean | Partial<AnimationConfig>,
): AnimationConfig => {
if (!config || typeof config === 'boolean') {
// 不转类型
return config === true
? cloneDeep(defaultAnimationOpenConfig)
: cloneDeep(defaultAnimationCloseConfig);
}
// 传入的是对象AnimationConfig
return merge(cloneDeep(defaultAnimationCloseConfig), config);
}
Example #2
Source File: theme.ts From LogicFlow with Apache License 2.0 | 6 votes |
updateTheme = (style: Theme) => {
let defaultStyle = cloneDeep(defaultTheme);
if (style) {
/**
* 为了不让默认样式被覆盖,改用merge
* 例如:锚点主题hover
* 用户传入
* lf.setTheme({
* anchor: {
* hover: {
* fill: 'red'
* }
* }
* })
*/
defaultStyle = merge(defaultStyle, style);
// Object.keys(style).forEach((key) => {
// defaultStyle[key] = { ...defaultStyle[key], ...style[key] };
// });
}
return defaultStyle;
}
Example #3
Source File: lib.ts From hexon with GNU General Public License v3.0 | 6 votes |
export function useTheme<N extends Exclude<keyof IGlobalTheme, "common">>(
id: N
) {
const { globalThemeRef } = inject(key)!
const themeRef = computed(() => {
const { common } = globalThemeRef.value
return merge(
{},
common,
globalThemeRef.value[id]?.self(common) as ReturnType<
IGlobalTheme[N]["self"]
>
)
})
return themeRef
}
Example #4
Source File: settings.ts From hexon with GNU General Public License v3.0 | 5 votes |
function withDefault(settings: Partial<ISettings> = {}) {
return merge({}, DEFAULT, settings)
}
Example #5
Source File: index.tsx From bext with MIT License | 5 votes |
_Form = withTheme( merge(cloneDeep(_Theme), { widgets: { SelectWidget, }, }), )
Example #6
Source File: UUICustomizeNode.tsx From UUI with MIT License | 4 votes |
export function IntrinsicNode<T extends keyof JSX.IntrinsicElements, N extends string>(tagName: T, nodeName: N, options: NodeCustomizeOptions) {
const nodeClassName = [options.prefix, options.name, nodeName].join(options.separator)
const Node = React.forwardRef((innerProps: JSX.IntrinsicElements[T], _ref) => {
const { customize } = (MemoNode as any)['CustomizeProps'] as Readonly<{ customize?: IntrinsicNodeCustomizeProps }>
const id = customize?.overrideId || innerProps.id
const className = (() => {
if (customize?.overrideClassName) return customize.overrideClassName
const innerClassName = innerProps.className
const finalClassName = classNames(nodeClassName, innerClassName, customize?.extendClassName)
return finalClassName
})()
const style = (() => {
if (customize?.overrideStyle) return customize.overrideStyle
const innerStyle = innerProps.style
const finalStyle = merge(innerStyle, customize?.extendStyle)
return isEmpty(finalStyle) ? undefined : finalStyle
})()
const dataAttributes = (() => {
if (!customize?.dataAttributes) return {}
/**
* @reference https://www.w3.org/TR/2008/REC-xml-20081126/#NT-Name
* TODO: // fix regex for supporting unicode
*/
const validDataAttributesCharactersRegex = /^([A-Za-z0-9-])*$/
let result = customize.dataAttributes
result = pickBy(result, (v, k) => validDataAttributesCharactersRegex.test(k))
result = mapKeys(result, (v, k) => `data-${k}`)
return result
})()
const children = (() => {
/**
* <select><option> only support string type children,
* if pass Fragments to children, it will show [Object Object] in html.
*/
if (tagName === 'option') return innerProps.children
/**
* <input> <textarea> <hr> is a void element tag and must not have `children`.
*/
if (['input', 'textarea', 'hr'].includes(tagName)) return undefined
if (customize?.overrideChildren) return customize.overrideChildren
return <>{customize?.extendChildrenBefore}{innerProps.children}{customize?.extendChildrenAfter}</>
})()
const ariaAttributes = (() => {
if (!customize?.ariaAttributes) return {}
return mapKeys(customize.ariaAttributes, (v, k) => `aria-${k}`)
})()
/**
* Merge both customize ref and component inner ref.
*/
const ref = mergeRefs([customize?.ref, _ref])
/**
* Merge both customize functions and component inner onXXX callback functions.
*/
const mergedCallbackFunctions = (() => {
const propsObj = innerProps as any
const customizeObj = (customize || {}) as any
const data: any = {}
const attrs = uniq([
...Object.keys(propsObj),
...Object.keys(customizeObj),
])
for (const attr of attrs) {
if (attr.startsWith('on')) {
const propsObjFunctionExist = !!(propsObj[attr] && typeof propsObj[attr] === 'function')
const customizeObjFunctionExist = !!(customizeObj[attr] && typeof customizeObj[attr] === 'function')
data[attr] = (...args: any[]) => {
if (propsObjFunctionExist) {
propsObj[attr](...args);
}
if (customizeObjFunctionExist) {
customizeObj[attr](...args);
}
};
}
}
return data
})()
return React.createElement(tagName, {
...omit(innerProps, 'children', 'ref', 'className', 'style'),
...mergedCallbackFunctions,
...dataAttributes,
...ariaAttributes,
ref,
id, className, style,
}, children)
})
const MemoNode = React.memo(Node)
MemoNode.type.displayName = `<UUI> [IntrinsicNode] ${nodeName}`
return MemoNode
}