-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add runHooks, deprecate runHook
DEPRECATED: `runHook` has been replaced with a more flexible `runHooks` function.
- Loading branch information
1 parent
22df8d6
commit 56b50ff
Showing
11 changed files
with
59 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
packages/core/src/actions/context/enhancers/hooks/runInstanceHooks.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Hookable, HookCallback, HooksDefinition } from '@foscia/core/hooks/types'; | ||
import { Arrayable, sequentialTransform, wrap } from '@foscia/shared'; | ||
|
||
/** | ||
* Sequentially run multiple hooks of a hookable object. | ||
* | ||
* @param hookable | ||
* @param hooks | ||
* @param event | ||
*/ | ||
export default async function runHooks<D extends HooksDefinition, K extends keyof D>( | ||
hookable: Hookable<D>, | ||
hooks: Arrayable<K>, | ||
event: D[K] extends HookCallback<infer E> ? E : never, | ||
) { | ||
await sequentialTransform(wrap(hooks).map((hook) => async () => { | ||
const hookCallbacks = hookable.$hooks?.[hook] ?? []; | ||
|
||
await sequentialTransform(hookCallbacks.map((callback) => async () => { | ||
await callback(event); | ||
})); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters