Skip to content

Commit

Permalink
fix: breaking revert UseCustomHook type
Browse files Browse the repository at this point in the history
  • Loading branch information
nmccready committed Aug 22, 2019
1 parent e8fe6f7 commit e7ee074
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ function setRef<T, A>(this: Store<T, A>, newState: T): void {

export type HookWork<T = undefined> = () => T;

export type UseCustomHook<T, A, WorkR = undefined> = [T, A] | [T, A, ...WorkR[]];

function useCustom<T, A, WorkR extends WorkR[] = undefined>(
this: Store<T, A>,
React: ReactLib,
hookWork?: HookWork<WorkR>
): UseCustomHook<T, A, WorkR> {
): [T, A] {
const newListener = React.useState()[1];
React.useEffect(() => {
this.listeners.push(newListener);
Expand All @@ -98,7 +96,7 @@ function useCustom<T, A, WorkR extends WorkR[] = undefined>(
if (hookWork) {
workAdditions = hookWork() || [];
}
return [this.state, this.actions, ...workAdditions];
return [this.state, this.actions, ...workAdditions] as [T, A];
}

function associateActions<T, InnerA, OuterA>(
Expand Down Expand Up @@ -132,7 +130,7 @@ const useStore = <
actions = baseActions,
initializer,
}: UseStoreProps<T, InnerA, OuterA, WorkR> = {} as UseStoreProps<T, InnerA, OuterA, WorkR>
): ((_?: HookWork<WorkR>) => UseCustomHook<T, InnerA, WorkR>) => {
): ((_?: HookWork<WorkR>) => [T, OuterA]) => {
const store = { state: initialState, listeners: [] } as Store<T, OuterA>;
store.setState = setState.bind(store);
store.setRef = setRef.bind(store);
Expand Down

0 comments on commit e7ee074

Please sign in to comment.