[wp-trac] [WordPress Trac] #21170: JavaScript actions and filters
WordPress Trac
wp-trac at lists.automattic.com
Fri Aug 10 22:12:54 UTC 2012
#21170: JavaScript actions and filters
----------------------------+--------------------------
Reporter: koopersmith | Owner: koopersmith
Type: task (blessed) | Status: new
Priority: normal | Milestone: 3.5
Component: General | Version: 3.4
Severity: normal | Resolution:
Keywords: |
----------------------------+--------------------------
Comment (by CaptainN):
SignalsLite.js now has every feature in the ticket (and then some, like
safe dispatching, addToTop, once, eachReturn handler for filtering) -
including priorities, namespaces and a way to cancel dispatch. And, it's
incredibly fast (crazy fast!). I did end up moving the safe dispatcher out
to it's own sub class (SignalDispatcher), because it was big, relies on
the DOM, and is frankly, not the fasted thing in the world (it's worth it
some cases! but maybe not every case). In its place is a simple trigger
method, which will just error out (like jQuery) if there's an error in a
listener.
Anyway, now that that base is done, maybe I'll take a stab at putting the
actual WordPress part around it - if there is any interest (I'm not sure
how far along any other implementations are).
Here's what the API might look like with Signals - you could keep things
string based if you wanted, and still expose the Signal feature set (which
I think has some advantages compared with period based namespacing, or the
full set of add methods you get with Signal priorities). Here's a quick
example of what could be done:
{{{
// add hook with chaining
// everything after addAction() is implemented and unit tested in
SignalsLite.js
$wp.hooks.addAction( "actionname" )
.ns( "myNamespace" )
.add( function() {} );
// additional adds can be property based (they don't have to be though)
$wp.hooks.actionname.myNamespace.add( function() {} );
// here's what priorities look like
$wp.hooks.addAction( "actionname" )
.priority( 10 )
.addToTop( function() {} );
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21170#comment:37>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list