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

WordPress Trac wp-trac at lists.automattic.com
Sun Jul 15 05:02:59 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 carldanley):

 It was fun to write! Couple of responses/questions:

 > The term "namespace" is used loosely in the above example.

 I agree, it was hard coming up with a term that encapsulates the object
 for both actions & filters. If you looked through the demo, they are
 essentially treated the same, except for how they are processed; the only
 slight variance is that filters can modify the value passed to it. That
 said, what do you think we could call these "objects" to help reduce
 confusion and standardize it? I will make the changes in comments/code to
 reflect the more accurate choice of words.

 > Having a complex structure/tree of actions is not necessary as they are
 all called at that specific time anyway (same as attaching events to the
 DOM).

 Are you referencing how the objects for filters & actions are bound with 3
 properties ( id, callbacks & children ) and sort of nested within each
 other? What if we did the following:
  * rework the internal storage to have 2 variables or keys for 'actions'
 and 'filters'.
  * when addAction() is called with a namespace, split it and find every
 hierarchical identifier to check to see if they exist, creating them, if
 they don't already exist, as you go, ie. you add "my.awesome.func", build
 an array of "levels" of identifiers ( [ 'my', 'my.awesome',
 'my.awesome.func' ] ) and then loop through the array. The identifiers
 could be hashed or literally written as the exact key with string filter
 to make sure there are no illegal characters as a key within the
 corresponding array.

 > Chaining might be useful in some cases, however not all methods can be
 "chainable" as applyFilters will have to return the filtered value.

 Just to point out that not all methods in jQuery are 'chainable' either,
 example; $( object ).height(); or $( object ).width(); I think for this
 particular case chaining makes good sense when doing something. In terms
 of useability, I'd rather see/type
 {{{
 $wp.hooks.addAction().addAction().addFilter().addFilter();
 }}}
 than
 {{{
 $wp.hooks.addAction();
 $wp.hooks.addAction();
 $wp.hooks.addFilter();
 $wp.hooks.addFilter();
 }}}

 It's easier to type the first example than the latter.

 What do you think? I appreciate the feedback and am willing to rework
 logic on this. I've been pumped every since lgedeon mentioned this ticket
 to me.

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


More information about the wp-trac mailing list