mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
refactor(react): replace prototype-walking and inferred class props (#1376)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
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>;
|
||||
}
|
||||
Reference in New Issue
Block a user