Voicemeeter-remote-frontend/src/utils/GetComponentState.ts
Maksym 3b2fb0264e modified: src/app/component/Bus.tsx
new file:   src/app/component/GainSlider.tsx
	modified:   src/app/component/Strip.tsx
	modified:   src/app/page.tsx
	new file:   src/utils/GetComponentState.ts
	new file:   src/utils/StopPropagation.ts
2024-10-16 18:19:10 +02:00

26 lines
798 B
TypeScript

export function getComponentState<
State extends Object,
StateDefaultValueException extends keyof State | ""
>(
initialValues: Partial<Omit<State, StateDefaultValueException>> | undefined,
defaultValues: State
) {
type InitialValuesType = Omit<State, StateDefaultValueException>;
// const { initialValues } = props;
const getValue = (name: keyof InitialValuesType) => {
if (initialValues === undefined) return defaultValues[name];
return initialValues[name] !== undefined
? defaultValues[name]
: initialValues[name];
};
const state = {
...(Object.fromEntries(
Object.entries(defaultValues).map(([name]) => [
name,
getValue(name as keyof InitialValuesType) as any,
])
) as InitialValuesType),
} as State;
return state;
}