[wp-trac] [WordPress Trac] #21170: JavaScript actions and filters
WordPress Trac
wp-trac at lists.automattic.com
Sat Jul 14 19:52:47 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):
Hi all,
I've been working with lgedeon to compile a list of requirements for this
library and then spent some time building something custom to support what
we might need. Long story short, let me jump into it:
=== Supported Features: ===
* Viable mixin structure with jQuery style dot namespacing
* Can add/remove namespaces like so:[[br]]'''$wp.hooks.addAction(
'some.crazy.action', func, 5 );'''[[br]]'''$wp.hooks.addAction(
'some.crazy', func2, 7);'''[[br]]'''$wp.hooks.removeAction(
'some.crazy.action' );'''
* Supports method chaining to create a jQuery-like function chain: [[br]]
'''$wp.hooks.addAction().addFilter().removeFilter().doAction();'''
* Priorities
* Ability to pass applicable callbacks through a process method of choice
so filters can be processed in predefined functions. The object that holds
the predefined filtering methods can also be worked to support extensions
in case developers want to write their own filtering methods. In example:
[[br]] '''$wp.hooks.doAction( 'some.action', { 'some' : 'data' },
'processingMethod' );''' [[br]]*note: also works for applyFilter().
* Currently has support for handling processing callbacks through a
default 'sequential' method; I do have plans to implement the following
methods:
* minValue
* maxValue
* allTrue
* allFalse
* No unique identifiers
* Anonymous functions are supported:[[br]]'''$wp.hooks.addAction(
'anonymous.funcs', function(){ /* do something */ }, 30 );'''
* Checks for a $wp global and binds itself to $wp.hooks
* $wp was used in case we decide to create other library functions, etc.
=== Supported Functions: ===
* '''addAction'''( action, callback, priority )
* '''doAction'''( action, data, processMethod )
* processMethod is currently string only but when I add support for
registering new process methods, I intend on adding support for passing a
defined or anonymous function directly through the processMethod
parameter.
* '''removeAction'''( action )
* '''addFilter'''( filter, callback, priority )
* '''applyFilter'''( filter, data, processMethod )
* see note for 'processMethod' under the doAction() function.
* '''removeFilter'''( filter )
* '''didAction'''( action )
* returns false or an integer count
* '''didFilter'''( filter )
* returns false or an integer count
If you have questions concerning logic and/or code implementation, please
refer to my code commenting first. I have tried to heavily comment the API
in areas that I thought may need further explanation or where I had ideas
for future improvements. I will patch the github as necessary.
Code can be found on my github here: https://github.com/carldanley
/WordPress-Action-Filter-Library
Demo can be temporarily found here: http://codebyter.dyndns.info/wp.hooks/
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21170#comment:28>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list