JavaScript Equivalent of WordPress do_action and apply_filters Functions

34 Views Asked by At

Is there a JavaScript library that provides functionality that is equivalent to WordPress' do_action and apply_filters functions?

I have a need to process zero or more callback functions from unknown sources that will be called at specific, named, processing points. I think the do_actions functionality can be handled through DOM events, but apply_filters must return data back to the caller and I am not aware of any native JavaScript mechanism to accomplish this.

Effectively, I need to be able to:

  1. Register one or more callback functions to be called at a specific process point based on a process hook name. Something like: register_filter( 'hook-get-controls', my_get_controls_callback );

  2. When the 'hook-get-controls' process point is reached, call all registered filters callback function with something like: controls = filter_callback_function( controls, hook_level_parameters );

Each filter may alter the value (first parameter) as they see fit and then return the altered value to the filter's caller.

I know I can build this but am wondering if there is a library already built (or maybe native JavaScript that I am not aware of).

Thanks in advance.

0

There are 0 best solutions below