mirror of
https://github.com/zoriya/v10.git
synced 2026-08-06 06:07:56 +00:00
21 lines
652 B
TypeScript
21 lines
652 B
TypeScript
import { isUndefined } from '@videojs/utils/predicate';
|
|
|
|
export function useSyncProps<Props extends object, Rest extends Record<string, unknown>>(
|
|
target: Props,
|
|
props: Partial<Props> & Rest,
|
|
defaults: Props
|
|
): Omit<Rest, keyof Props> {
|
|
const rest: Record<string, unknown> = {};
|
|
|
|
for (const key in props) {
|
|
if (key in defaults) {
|
|
const value = isUndefined(props[key]) ? (defaults as Record<string, unknown>)[key] : props[key];
|
|
if (target[key as keyof typeof target] !== value) target[key as keyof typeof target] = value as any;
|
|
} else {
|
|
rest[key] = props[key];
|
|
}
|
|
}
|
|
|
|
return rest as Omit<Rest, keyof Props>;
|
|
}
|