Skip to content

Commit

Permalink
docs(README): merge hooks together
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 9, 2020
1 parent 16c69ea commit 39d986e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ I find myself re-writing the code for hooks in multiple packages, so decided to
- [exec(lifecycle: 'before' | 'after', action: string, ...data: any[])](#execlifecycle-before--after-action-string-data-any)
- [remove (lifecycle: 'before' | 'after', action: string, handler: HooksHandler | string)](#remove-lifecycle-before--after-action-string-handler-hookshandler--string)
- [clear(lifecycle: 'before' | 'after', action?: string)](#clearlifecycle-before--after-action-string)
- [merge (hooks: Hooks): void](#merge-hooks-hooks-void)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -116,6 +117,19 @@ hooks.clear('before')
hooks.clear('before', 'save')
```

#### merge (hooks: Hooks): void
Merge hooks from an existing hooks instance. Useful during class inheritance.

```ts
const hooks = new Hooks()
hooks.add('before', 'save', function () {})

const hooks1 = new Hooks()
hooks1.merge(hooks)

await hooks1.exec('before', 'save', [])
```

[circleci-image]: https://img.shields.io/circleci/project/github/poppinss/hooks/master.svg?style=for-the-badge&logo=circleci
[circleci-url]: https://circleci.com/gh/poppinss/hooks "circleci"

Expand Down

0 comments on commit 39d986e

Please sign in to comment.