@russmedia/hooks
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Russmedia Hooks

A lightweight & efficient EventManager for JavaScript mimicing the functionality of @wordpress/hooks, but with the ability to await async actions/filters to be finished before proceeding.

Installation

Install the module

npm install @russmedia/hooks --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.

Usage

In your Javascript project, use russmedia-hooks as follows:

import { createHooks } from '@russmedia/hooks'

const hooks = createHooks()
hooks.addAction(...)
await hooks.doAction(...)
...

You may also use the shorthand versions.

import { addAction, doAction } from '@russmedia/hooks'

addAction(...)
await doAction(...)
...

The basic functionality is similar to how WordPress handles hooks.

API Usage

  • createHooks()
  • addAction( 'hookName', callback, priority )
  • addFilter( 'hookName', callback, priority )
  • doAction( 'hookName', arg1, arg2, moreArgs, finalArg )
  • applyFilters( 'hookName', content, arg1, arg2, moreArgs, finalArg )
  • actions
  • filters

See hooks.spec.ts for basic examples on how to set up and trigger actions/filters.

Readme

Keywords

none

Package Sidebar

Install

npm i @russmedia/hooks

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

62.8 kB

Total Files

26

Last publish

Collaborators

  • julianmar
  • russmediadigital
  • mwidmann