From fd3e99d2c55b99a1c929ecfcdca93e50715f8608 Mon Sep 17 00:00:00 2001 From: Adam Yost Date: Sat, 13 Jul 2024 11:31:43 -0600 Subject: [PATCH] remove hardcoded value option --- packages/manager/package.json | 2 +- packages/manager/src/react.tsx | 27 ++++++--------------------- packages/manager/src/types.ts | 4 ---- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/packages/manager/package.json b/packages/manager/package.json index f67307d..06102c7 100644 --- a/packages/manager/package.json +++ b/packages/manager/package.json @@ -1,6 +1,6 @@ { "name": "@tectonica/manager", - "version": "1.0.1", + "version": "1.1.0", "module": "dist/esm/index.js", "types": "dist/types/index.d.ts", "exports": { diff --git a/packages/manager/src/react.tsx b/packages/manager/src/react.tsx index 56bf937..84bdc01 100644 --- a/packages/manager/src/react.tsx +++ b/packages/manager/src/react.tsx @@ -8,7 +8,6 @@ import { GetKeyFunc, GetKeyType, GetValueFunc, - GetValueType, GlobalKey, InferManagerEvents, ManagerConstructorHook, @@ -99,8 +98,8 @@ export function createValueListenerHook< managerClass: ManagerClass, eventName: EventName, getKey: GetKeyType, InferManagerEvents>, EventName, ArgsType>, - getValue: GetValueType, InferManagerEvents>, EventName, ReturnType>, - getServerValue: GetValueType, InferManagerEvents>, EventName, ReturnType> = getValue + getValue: GetValueFunc, InferManagerEvents>, EventName, ReturnType>, + getServerValue: GetValueFunc, InferManagerEvents>, EventName, ReturnType> = getValue ): (...args: ArgsType[]) => ReturnType { const keyGetter = (typeof getKey === 'function' ? getKey : (_mgr, ..._args) => getKey) as GetKeyFunc< InstanceType, @@ -109,20 +108,6 @@ export function createValueListenerHook< ArgsType > - const valueGetter = (typeof getValue === 'function' ? getValue : (..._args: any[]) => getValue) as GetValueFunc< - InstanceType, - InferManagerEvents>, - EventName, - ReturnType - > - - const serverValueGetter = (typeof getServerValue === 'function' ? getServerValue : (..._args: any[]) => getServerValue) as GetValueFunc< - InstanceType, - InferManagerEvents>, - EventName, - ReturnType - > - const ManagerContext = getManagerContext(managerClass) return (...args: ArgsType[]): ReturnType => { @@ -144,11 +129,11 @@ export function createValueListenerHook< ) const getSnapshot = useCallback(() => { - return valueGetter({ manager, eventName, key, data: undefined }) + return getValue({ manager, eventName, key, data: undefined }) }, [manager, key]) const getServerSnapshot = useCallback(() => { - return serverValueGetter({ manager, eventName, key, data: undefined }) + return getServerValue({ manager, eventName, key, data: undefined }) }, [manager, key]) const value = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) @@ -200,8 +185,8 @@ export function createGlobalValueListenerHook< >( managerClass: ManagerClass, eventName: EventName, - getValue: GetValueType, InferManagerEvents>, EventName, ReturnType>, - getServerValue?: GetValueType, InferManagerEvents>, EventName, ReturnType> + getValue: GetValueFunc, InferManagerEvents>, EventName, ReturnType>, + getServerValue?: GetValueFunc, InferManagerEvents>, EventName, ReturnType> ): () => ReturnType { return createValueListenerHook(managerClass, eventName, GlobalKey, getValue, getServerValue) } diff --git a/packages/manager/src/types.ts b/packages/manager/src/types.ts index 05ce4eb..d75379f 100644 --- a/packages/manager/src/types.ts +++ b/packages/manager/src/types.ts @@ -58,10 +58,6 @@ export type GetValueFunc, E extends EventsDef data: ListenerData ) => ValueType -export type GetValueType, E extends EventsDef, EventName extends ManagerEventTypeName, ValueType> = - | GetValueFunc - | ValueType - export type EventHandler> = (data: ManagerEventTypeData) => void export type EffectListener, E extends EventsDef, EventName extends ManagerEventTypeName> = (data: ListenerData) => void