JSPM

@wordpress/hooks

0.1.0-beta.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 175367
  • Score
    100M100P100Q220125F
  • License GPL-2.0+

WordPress Hooks library

Package Exports

  • @wordpress/hooks

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@wordpress/hooks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

WP-JS-Hooks

A lightweight & efficient EventManager for JavaScript in WordPress.

API Usage

API functions can be called via the global wp.hooks like this wp.hooks.addAction(), etc.

  • addAction( 'hook', 'vendor/plugin/function', callback, priority )
  • addFilter( 'hook', 'vendor/plugin/function', callback, priority )
  • removeAction( 'hook', 'vendor/plugin/function' )
  • removeFilter( 'hook', 'vendor/plugin/function' )
  • removeAllActions( 'hook' )
  • removeAllFilters( 'hook' )
  • doAction( 'hook', arg1, arg2, moreArgs, finalArg )
  • applyFilters( 'hook', content, arg1, arg2, moreArgs, finalArg )
  • doingAction( 'hook' )
  • doingFilter( 'hook' )
  • didAction( 'hook' )
  • didFilter( 'hook' )
  • hasAction( 'hook' )
  • hasFilter( 'hook' )

Background

See ticket #21170 for more information.

Features

  • Fast and lightweight.
  • Priorities system ensures hooks with lower integer priority are fired first.
  • Uses native object hash lookup for finding hook callbacks.
  • Utilizes insertion sort for keeping priorities correct. Best Case: O(n), worst case: O(n^2)