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

WordPress Trac wp-trac at lists.automattic.com
Thu Jul 12 23:37:52 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 CaptainN):

 Yeah, the JS way is to pass by reference, for sure. I added support to
 SignalLite anyway, because it was a gap (you can even filter by value):

 {{{
 var signaled = new SignalLite();

 var value_tofilter = "some value of stuff";

 var wpFilter = {
         value_filter: new SignalLite( null,
                 function( value, args ) {
                         value_tofilter = value;
                         // set the argument so it'll pass modified to the
 next listener
                         args[ 0 ] = value;
                 }
         )
 };

 wpFilter.value_filter.add( function( value ) {
         value = value.replace( "some", "THE" );
         return value;
 } );

 wpFilter.value_filter.add( function( value ) {
         value = value.replace( "stuff", "things" );
         return value;
 } );

 wpFilter.value_filter.dispatch( value_tofilter );

 equal( value_tofilter, "THE value of things", '"some" should be "THE" and
 "stuff" should be "things"' );
 }}}

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


More information about the wp-trac mailing list