A lightweight JavaScript event manager for WordPress
See core ticket #21170 and our WordSesh talk.
wp.hooks.addAction( 'tag', callback, priority );
wp.hooks.addFilter( 'tag', callback, priority );
wp.hooks.removeAction( 'tag', callback );
wp.hooks.removeFilter( 'tag', callback );
wp.hooks.doAction( 'tag', arg1, arg2, arg3 ); // any number of args can be included
wp.hooks.applyFilters( 'tag', content );
- Fast and lightweight, ~1.5kb
- Vanilla JS with no dependencies
- 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)