[wp-trac] [WordPress Trac] #21170: JavaScript actions and filters

WordPress Trac noreply at wordpress.org
Mon Jan 27 01:55:26 UTC 2014


#21170: JavaScript actions and filters
-----------------------------+-----------------------------
 Reporter:  koopersmith      |       Owner:  koopersmith
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Future Release
Component:  General          |     Version:  3.4
 Severity:  normal           |  Resolution:
 Keywords:  2nd-opinion      |     Focuses:  javascript
-----------------------------+-----------------------------

Comment (by azaozz):

 In my opinion the biggest advantages of having a dedicated hooks API are:

 - Similarity to the PHP hooks. It's true that more and more (plugin)
 developers understand JS better, but there are a lot that will find this
 very desirable.

 - Interoperability. None of the event APIs we can use allow a callback to
 be scheduled to run before or after another callback, even before the
 second callback is defined. In the PHP actions and filters this is done
 with 'priority'. It has its limitations but has been working really well
 for about 10 years. Considering that some hooks would be used by core plus
 2-3-4 plugins, having proority be great.

 > Has anyone looked through core for places that are good candidates for
 adding some hooks?

 Heartbeat works only with hooks (both in PHP and JS), now autosave has
 several hooks too.

 > I think we would want to support a context parameter

 Agreed, having a scope can be quite handy and will make this better.

 > If we are going to create a dependency...

 Don't think we need a dependency. The current patch is fast, simple and
 works very well.

 > ...we should build the core library so that it can be used under a
 separate namespace

 This may be handy in some cases however there are already jQuery custom
 events, jQiery callbacks, and Backbone events that can be used.

 > ...it would be nice if subscribers could easily clean up references to
 the event bus. This is the reason that Backbone added the listenTo and
 stopListening

 Yes, I see this rather as supporting removing hooks in "bulk" like
 jQuery's `$(document').off('.my-hooks')`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/21170#comment:86>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list