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

WordPress Trac wp-trac at lists.automattic.com
Sat Jul 7 01:48:11 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 azaozz):

 Replying to [comment:19 CaptainN]:
 > It's a lot of very small objects (as apposed to a lot of strings in
 other models)

 Yes, I can see some advantages in that. If each hook name refers to an
 instance, we could have couple of basic methods there, add(), remove(),
 fired(), etc. even if add() is just [].splice() and remove is [].slice().

 The important thing is to keep the callbacks (which could be instances of
 a small "callback" class) in a true JS array so the priority is
 maintained. Unlike PHP, JS doesn't guarantee that ordering in objects will
 be maintained.

 > You could also use a factory method of some kind to construct those (and
 to add/remove custom actions so plugin authors wouldn't have to
 instantiate any Signal instances directly).

 Yeah, that's a must. Another somewhat similar implementation of custom
 events is in TinyMCE. It uses instances for both events and callbacks and
 seems pretty well build (doesn't have priority for the callbacks but has
 `addToTop()` method):
 http://www.tinymce.com/wiki.php/API3:class.tinymce.util.Dispatcher,
 code at:
 https://github.com/tinymce/tinymce/blob/master/jscripts/tiny_mce/classes/util/Dispatcher.js

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21170#comment:20>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list