@poppinss/hooks
Advanced tools
Comparing version 7.1.1-5 to 7.1.1-6
@@ -31,2 +31,6 @@ import { HookHandler, HookHandlerProvider } from './types.js'; | ||
/** | ||
* Execute handlers in reverse order | ||
*/ | ||
runReverse(...data: HookArgs): Promise<void>; | ||
/** | ||
* Execute cleanup actions | ||
@@ -33,0 +37,0 @@ */ |
@@ -75,5 +75,5 @@ /* | ||
/** | ||
* Execute handlers | ||
* Executing hooks | ||
*/ | ||
async run(...data) { | ||
async #exec(reverse, data) { | ||
if (this.#state !== 'idle') { | ||
@@ -86,6 +86,4 @@ return; | ||
} | ||
/** | ||
* Execute handlers | ||
*/ | ||
for (let handler of this.#hookHandlers) { | ||
const handlers = reverse ? Array.from(this.#hookHandlers).reverse() : this.#hookHandlers; | ||
for (let handler of handlers) { | ||
if (this.#filter(handler.name)) { | ||
@@ -102,2 +100,14 @@ const result = await (typeof handler === 'function' | ||
/** | ||
* Execute handlers | ||
*/ | ||
async run(...data) { | ||
return this.#exec(false, data); | ||
} | ||
/** | ||
* Execute handlers in reverse order | ||
*/ | ||
async runReverse(...data) { | ||
return this.#exec(true, data); | ||
} | ||
/** | ||
* Execute cleanup actions | ||
@@ -104,0 +114,0 @@ */ |
{ | ||
"name": "@poppinss/hooks", | ||
"version": "7.1.1-5", | ||
"version": "7.1.1-6", | ||
"description": "A no brainer hooks module for execute before/after lifecycle hooks", | ||
@@ -44,3 +44,3 @@ "main": "build/index.js", | ||
"@adonisjs/tsconfig": "^1.1.8", | ||
"@commitlint/cli": "^17.7.1", | ||
"@commitlint/cli": "^17.7.2", | ||
"@commitlint/config-conventional": "^17.7.0", | ||
@@ -51,6 +51,6 @@ "@japa/assert": "^2.0.0-1", | ||
"@swc/core": "1.3.82", | ||
"@types/node": "^20.6.3", | ||
"@types/node": "^20.8.3", | ||
"c8": "^8.0.1", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.50.0", | ||
"eslint": "^8.51.0", | ||
"github-label-sync": "^2.3.1", | ||
@@ -57,0 +57,0 @@ "husky": "^8.0.3", |
@@ -75,2 +75,11 @@ # @poppinss/hooks | ||
To run hooks in the reverse order, you can use the `runner.runReverse` method. | ||
```ts | ||
const hooks = new Hooks() | ||
const runner = hooks.runner('saving') | ||
await runner.runReverse() | ||
``` | ||
### Passing data to hooks | ||
@@ -77,0 +86,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18934
345
191