[wp-trac] [WordPress Trac] #21170: JavaScript actions and filters
WordPress Trac
noreply at wordpress.org
Mon Sep 25 19:06:20 UTC 2017
#21170: JavaScript actions and filters
-----------------------------+-------------------------
Reporter: koopersmith | Owner:
Type: feature request | Status: assigned
Priority: normal | Milestone: 4.9
Component: General | Version: 3.4
Severity: normal | Resolution:
Keywords: | Focuses: javascript
-----------------------------+-------------------------
Comment (by westonruter):
Replying to [comment:177 adamsilverstein]:
> > would it not be a better architectural pattern to instead introduce
hooks as something that can be instantiated onto a specific object
>
> @westonruter intriguing idea, i'm not sure it lets you remove hooks the
way we want? The namespaces is mostly so you CAN easily remove hooks by
name (no matter who added them), a requirement that was brought up during
development.
Sure, you'd just remove the hooks on the object that you added `wp.Hooks`
to begin with. There would be no need for a hook namespace because each
object that extends `wp.Hooks` would have its own set of hooks. For
example, given:
{{{#!js
var component = {};
_.extend( component, wp.Hooks );
var fooFilter = function( x ){
return x + ' foo\'d!';
};
component.addFilter( 'foo', fooFilter );
}}}
Then that `foo` filter can be removed with either:
{{{#!js
component.removeFilter( 'foo', fooFilter );
}}}
Or if the reference to `fooFilter` is not available then this can be used
instead:
{{{#!js
component.removeAllFilters( 'foo' );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/21170#comment:178>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list