lodash-es#omit TypeScript Examples
The following examples show how to use
lodash-es#omit.
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: Button.tsx From UUI with MIT License | 6 votes |
Button = UUIFunctionComponent({
name: 'Button',
nodes: {
Root: 'button',
LoadingSpinner: LoadingSpinner,
Content: 'div',
},
propTypes: ButtonPropTypes,
}, (props: ButtonFeatureProps & ButtonStylingProps, { nodes, NodeDataProps }) => {
const { Root, LoadingSpinner, Content } = nodes
const ref = useRef<HTMLElement | null>(null)
return (
<Root
{...NodeDataProps({
'type': props.styling?.type,
'disabled': !!props.disabled,
'loading': !!props.loading,
})}
role="button"
{...omit(props, 'customize', 'styling', 'className', 'style', 'loading', 'prefix', 'separator')}
onKeyDown={(event) => {
switch (event.keyCode) {
case KeyCode.Enter:
case KeyCode.SpaceBar:
ref.current?.click()
break
default:
// do nothing
}
}}
>
{props.loading ? <LoadingSpinner animate width={14} height={14} /> : null}
{props.children ? <Content>{props.children}</Content> : null}
</Root>
)
})
Example #2
Source File: code-generator.ts From openapi-generator-typescript with MIT License | 6 votes |
export function generate_parent_schema_definition(
schemasEntriesDiscriminator: ReadonlyArray<
readonly [string, DiscriminatorSchema]
>
) {
const result = schemasEntriesDiscriminator.map(
([name, schema]) =>
`export interface ${identifier(name)} ${getObject({
...schema,
properties: {
// 这里不是很有必要
[schema.discriminator.propertyName]: {
type: 'string',
enum: Object.keys(schema.discriminator.mapping ?? {}),
},
...omit(schema.properties, [schema.discriminator.propertyName]),
},
})}`
);
return `namespace _parent_schema_definition {
${addIndentLevel(result.join('\n'))}
}
`;
}
Example #3
Source File: Radio.tsx From UUI with MIT License | 5 votes |
BaseRadio = UUIFunctionComponent({
name: "Radio",
nodes: RadioNodes,
propTypes: RadioPropTypes,
}, (props: RadioFeatureProps<string | number>, { nodes, NodeDataProps }) => {
const { Root, Input, Indicator, Label } = nodes
const context = useContext(RadioGroupContext)
const checked = useMemo(() => {
if (context) {
return props.value === context.value
} else {
return props.checked
}
}, [context, props.checked, props.value])
const focused = useMemo(() => {
if (context) {
return context.focusValue === props.value
}
}, [context, props.value])
return (
<Root
role="radio"
aria-checked={checked}
{...NodeDataProps({
'disabled': !!props.disabled,
'checked': !!checked,
})}
>
<Input
tabIndex={context ? (focused ? 0 : -1) : 0}
name={props.name}
type='radio'
disabled={props.disabled}
value={props.value}
checked={checked}
onChange={() => context?.onChange(props.value)}
{...(context ? {} : omit(props, 'className', 'style', 'type', 'label', 'customize'))}
onFocus={context?.onFocus || props.onFocus}
onBlur={context?.onBlur || props.onBlur}
/>
<Indicator></Indicator>
<Label>{props.label}</Label>
</Root>
)
})
Example #4
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
}
Example #5
Source File: publish-dialog.tsx From bext with MIT License | 4 votes |
PublishDialog: FC<{ hide?: () => void }> = ({ hide }) => {
const { draft } = useDraft();
const { notify, dismissNotification } = useNotifications();
const [message, setMessage] = useState('');
const [loading, setLoading] = useState(false);
const onPublish = () => {
const notifyId = uniqueId('export-notify');
const loading = (message: string) =>
notify({
status: 'loading',
message,
dismissAfter: 0,
dismissible: false,
id: notifyId,
});
const branchName = Math.random().toString(16).slice(2);
const user = user$.getValue()!.user!;
const octokit = octokit$.getValue()!;
setLoading(true);
of(draft!)
.pipe(
switchMap((draft) => {
if (!(draft.id && draft.name && draft.version)) {
return throwError(() => new Error('请填写完整 ID,名称,版本号'));
}
loading('编译中');
return from(
excuteCompile({
meta: {
id: draft.id,
name: draft.name,
version: draft.version!,
source: draft.source!,
defaultConfig: draft.defaultConfig,
},
}),
).pipe(
catchError(() =>
throwError(() => new Error('编译错误,请打开控制台查看详情')),
),
switchMap(() => {
loading('获取仓库信息');
return from(
octokit.repos.get({
owner: user.login!,
repo: packageJson.metaRepository.repo,
}),
).pipe(
catchError((error) => {
if (error.status === 404) {
loading('Fork 仓库');
return from(
octokit.repos.createFork({
owner: packageJson.metaRepository.owner,
repo: packageJson.metaRepository.repo,
}),
).pipe(
concatMap(() => {
loading('查询 Fork 结果');
return timer(5000, 10000).pipe(
switchMap(() =>
from(
octokit.repos.get({
owner: user.login!,
repo: packageJson.metaRepository.repo,
}),
).pipe(catchError(() => EMPTY)),
),
take(1),
);
}),
);
}
return throwError(() => new Error('查询仓库信息失败'));
}),
);
}),
switchMap(({ data: repo }) => {
loading('创建分支');
return from(
octokit.git.createRef({
owner: repo.owner.login,
repo: repo.name,
ref: `refs/heads/${branchName}`,
sha: packageJson.metaRepository.base,
}),
);
}),
switchMap(() => {
loading('同步主分支');
return from(
octokit.repos.mergeUpstream({
owner: user.login!,
repo: packageJson.metaRepository.repo,
branch: branchName,
}),
);
}),
switchMap(() => {
loading('获取文件信息');
return from(
octokit.repos.getContent({
owner: user.login,
repo: packageJson.metaRepository.repo,
path: `meta/${draft.id}.json`,
ref: branchName,
}),
).pipe(
map(({ data }) =>
Array.isArray(data) ? data[0].sha : data.sha,
),
catchError((err) =>
err?.status === 404 ? of(undefined) : throwError(() => err),
),
);
}),
switchMap((sha) => {
const prepareDraft = omit(cloneDeep(draft), 'id');
prepareDraft.detail = DOMPurify.sanitize(
prepareDraft.detail || '',
);
return from(
octokit.repos.createOrUpdateFileContents({
owner: user.login,
repo: packageJson.metaRepository.repo,
path: `meta/${draft.id}.json`,
message,
content: Base64.encode(JSON.stringify(prepareDraft)),
sha,
branch: branchName,
}),
);
}),
switchMap(() =>
from(
octokit.pulls.create({
owner: packageJson.metaRepository.owner,
repo: packageJson.metaRepository.repo,
title: `[${draft.name}] ${draft.synopsis}`,
head: `${user.login}:${branchName}`,
base: 'master',
maintainer_can_modify: true,
}),
),
),
);
}),
finalize(() => {
dismissNotification(notifyId);
setLoading(false);
hide?.();
}),
catchError((err) => {
notify({
status: 'error',
message: err?.message || err?.toString(),
dismissible: true,
dismissAfter: 3000,
});
return EMPTY;
}),
)
.subscribe(() => {
notify({
status: 'success',
message: '提交成功,请返回查看、预览',
});
});
};
return (
<>
<TextField
description="将会在切换版本时展示"
value={message}
onChange={(_, text) => setMessage(text || '')}
disabled={loading}
/>
<DialogFooter>
<PrimaryButton
className="ml-auto"
onClick={onPublish}
disabled={loading || !message.length}
>
发布
</PrimaryButton>
</DialogFooter>
</>
);
}