Skip to content

Commit

Permalink
feat(overmind-vue): pass callback to other hooks as well
Browse files Browse the repository at this point in the history
  • Loading branch information
christianalfoni committed Jan 23, 2021
1 parent f674c8b commit 8b2d584
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/node_modules/overmind-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,30 @@ export function createStateHook<Config extends IConfiguration>(): StateHook<Conf
}) as any
}

export function createActionsHook<Config extends IConfiguration>() {
return (): Overmind<Config>["actions"] => {
export interface ActionsHook<Config extends IConfiguration> {
(): Ref<Overmind<Config>["actions"]>;
<CB extends (actions: Overmind<Config>["actions"]) => object>(cb: CB): CB extends (actions: Overmind<Config>["actions"]) => infer O ? O extends object ? Ref<O> : never : never;
}

export function createActionsHook<Config extends IConfiguration>(): ActionsHook<Config> {
return ((cb?: any): Overmind<Config>["actions"] => {
const overmindInstance = inject<any>('overmind')

return overmindInstance.actions
}
return cb ? cb(overmindInstance.actions) : overmindInstance.actions
}) as any
}

export function createEffectsHook<Config extends IConfiguration>() {
return (): Overmind<Config>["effects"] => {
export interface EffectsHook<Config extends IConfiguration> {
(): Ref<Overmind<Config>["effects"]>;
<CB extends (effects: Overmind<Config>["effects"]) => object>(cb: CB): CB extends (effects: Overmind<Config>["effects"]) => infer O ? O extends object ? Ref<O> : never : never;
}

export function createEffectsHook<Config extends IConfiguration>(): EffectsHook<Config> {
return ((cb?: any): Overmind<Config>["effects"] => {
const overmindInstance = inject<any>('overmind')

return overmindInstance.effects
}
return cb ? cb(overmindInstance.effects) : overmindInstance.effects
}) as any
}

export function createReactionHook<Config extends IConfiguration>() {
Expand Down
1 change: 1 addition & 0 deletions packages/node_modules/overmind/src/internalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type NestedPartial<T> = T extends Function
export type Options = {
delimiter?: string
name?: string
devEnv?: string
devtools?: string | boolean
logProxies?: boolean
hotReloading?: boolean
Expand Down

0 comments on commit 8b2d584

Please sign in to comment.