[wp-trac] [WordPress Trac] #21170: JavaScript actions and filters
WordPress Trac
wp-trac at lists.automattic.com
Sat Jul 14 22:15: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):
Looks very interesting. Couple of "first look" notes:
- The complex namespace implementation looks good. However I'm not sure we
need to go there. The term "namespace" is used loosely in the above
example. It works about the same like in jQuery event namespacing and is
more of a "unique identifier" than a real namespace. (That's my fault btw,
should have called it "identifier"). It can be implemented as above:
`addAction('actionname.identifier', function(args){...});` or as separate
arg: `addAction('actionname', 'identifier', function(args){...});`.
Generally the actions (and filters) are a way to call specific function
at a specific time. 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).
Perhaps if we are implementing "stop execution if any callback returns
false" (and that's a big '''if''', since there's no such functionality in
the PHP version), having a more complex structure of identifiers
(namespaces) would allow for one branch to be stopped while other branches
continue. Still, that would be a "border case" functionality. (Normally a
plugin would register one callback with `addAction` and would expect it to
be executed every time when `doAction` is triggered. For a "tree"
structure to work, plugins would have to share the "branch names" which is
quite hard to do, or we will end up with a big tree with many branches
that have only one "leaf" (callback) each, and that's not useful).
- Not sure about support for 'processingMethod'. Imho it's better/more
important to be able to directly set the scope for the callbacks (all
similar libraries support that). It would be good if you can add some
usage examples for this.
- Chaining might be useful in some cases, however not all methods can be
"chainable" as `applyFilters` will have to return the filtered value.
Maybe it would be better to leave chaining off and return true/false on
whether `addAction/addFilter/removeAction/removeFilter` was successful or
not.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21170#comment:29>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list