Skip to content

Commit

Permalink
remove hardcoded value option
Browse files Browse the repository at this point in the history
  • Loading branch information
swimmadude66 committed Jul 13, 2024
1 parent d8994b7 commit fd3e99d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/manager/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
27 changes: 6 additions & 21 deletions packages/manager/src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
GetKeyFunc,
GetKeyType,
GetValueFunc,
GetValueType,
GlobalKey,
InferManagerEvents,
ManagerConstructorHook,
Expand Down Expand Up @@ -99,8 +98,8 @@ export function createValueListenerHook<
managerClass: ManagerClass,
eventName: EventName,
getKey: GetKeyType<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ArgsType>,
getValue: GetValueType<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType>,
getServerValue: GetValueType<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType> = getValue
getValue: GetValueFunc<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType>,
getServerValue: GetValueFunc<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType> = getValue
): (...args: ArgsType[]) => ReturnType {
const keyGetter = (typeof getKey === 'function' ? getKey : (_mgr, ..._args) => getKey) as GetKeyFunc<
InstanceType<typeof managerClass>,
Expand All @@ -109,20 +108,6 @@ export function createValueListenerHook<
ArgsType
>

const valueGetter = (typeof getValue === 'function' ? getValue : (..._args: any[]) => getValue) as GetValueFunc<
InstanceType<typeof managerClass>,
InferManagerEvents<InstanceType<typeof managerClass>>,
EventName,
ReturnType
>

const serverValueGetter = (typeof getServerValue === 'function' ? getServerValue : (..._args: any[]) => getServerValue) as GetValueFunc<
InstanceType<typeof managerClass>,
InferManagerEvents<InstanceType<typeof managerClass>>,
EventName,
ReturnType
>

const ManagerContext = getManagerContext(managerClass)

return (...args: ArgsType[]): ReturnType => {
Expand All @@ -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)
Expand Down Expand Up @@ -200,8 +185,8 @@ export function createGlobalValueListenerHook<
>(
managerClass: ManagerClass,
eventName: EventName,
getValue: GetValueType<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType>,
getServerValue?: GetValueType<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType>
getValue: GetValueFunc<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType>,
getServerValue?: GetValueFunc<InstanceType<typeof managerClass>, InferManagerEvents<InstanceType<typeof managerClass>>, EventName, ReturnType>
): () => ReturnType {
return createValueListenerHook<ManagerClass, EventName, never, ReturnType>(managerClass, eventName, GlobalKey, getValue, getServerValue)
}
Expand Down
4 changes: 0 additions & 4 deletions packages/manager/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ export type GetValueFunc<Manager extends AbstractManager<E>, E extends EventsDef
data: ListenerData<Manager, E, EventName>
) => ValueType

export type GetValueType<Manager extends AbstractManager<E>, E extends EventsDef, EventName extends ManagerEventTypeName<E>, ValueType> =
| GetValueFunc<Manager, E, EventName, ValueType>
| ValueType

export type EventHandler<E extends EventsDef, EventName extends ManagerEventTypeName<E>> = (data: ManagerEventTypeData<E, EventName>) => void

export type EffectListener<Manager extends AbstractManager<E>, E extends EventsDef, EventName extends ManagerEventTypeName<E>> = (data: ListenerData<Manager, E, EventName>) => void
Expand Down

0 comments on commit fd3e99d

Please sign in to comment.