Hi Martin,

Bug filed!
http://bugzilla.qooxdoo.org/show_bug.cgi?id=3945

I don't think you need to worry too much about it.

*It's not a replacement for "addListener" and "bind". *
I've called them something different *on purpose*.

Events and bindings get removed by two different mechanism currently:

1. They are automatically removed upon disposal of the source object.
2. They are manually removed by custom clean up code in disposers, when the
source object outlives whatever it is bound to

I'm just suggesting a third option:

3. You use these utility methods, so you don't have to write custom clean up
code.

-- Greetings
-- Ralf ( @ gong.nl  )


2010/8/2 Martin Wittemann <martin.wittem...@1und1.de>

> Hello Ralf,
>
> thanks for the details. Could you open up a bug report for that? That a
> thing i need to think about a but because i'm not sure if we want that
> behavior in every situation. Additionally, I currently have no idea of the
> side effects of that. Maybe is slows down the shutdown, maybe it has a big
> memory impact, ... i currently have no idea and during testing and building
> a release, its hard to get time for that.
>


Take your qx.data.controller.Form. It had a bug (which has been fixed now),
where it forget to remove the bindings when the object was disposed.
This Mixin simply takes that logic and makes it generally available to every
qx.core.Object

So in those cases it simply prevents code duplication.
I'm not sure if you need that behavior in all cases.

Here's another simple example situation where events are at play.
Managing the disposal of its events manually:

//////////////////////////////////////////
qx.Class.define("app.AccountWindow",{
extend:qx.ui.window.Window,
construct:function( vRecordId ){
/////////////////////////////////////////////////

  this.base(arguments, "Edit this record..");
  this.setShowStatus( true );
  this.__listeners = [];

  // there is a 'cached' store for every record
  var vStore = app.Config.getTable( 'Account' ).getRecord( vRecordId );

  this.__listeners.push( vStore.addListener('loaded', function(){
    this.setStatus('record has been loaded');
  }, this));

  this.__listeners.push( vStore.addListener('saved', function(){
    this.setStatus('record has been saved');
  }, this);

  /* add actual form to the window here */


//////////////////////
},destruct:function(){
//////////////////////

  // removing events I set up between the store and the status-bar
  this.__listeners.forEach( function( vId ){
this.__store.removeListenerById( vId ); } );


////
}});
////
















>
> Regards,
> Martin
>
>
> Am 02.08.2010 um 16:31 schrieb Ralf Nieuwenhuijsen:
>
> *Hi all,*
>
> Below is a *mixin* for the *automatic removal of remote listeners &
> bindings* on dispose.
> Rather than calling [target].addListener, [target].addListenerOnce  or
> [source].bind you call either of these two methods:
>
>   [myObject].addListenerTo( [target], [event], [func], [context] )
>   [myObject].addListenerOnceTo( [target], [event], [func], [context] )
>   [myObject].addBindingTo( [source], [sourceProperty], [target],
> [targetProp] )
>
> Now when [myObject] is *disposed*, the listeners and bindings created on
> its behalf are removed.
>
> Also, when adding events and the [context] you want is "this", you don't
> need to specify it anymore.
> Which makes sense, since we know for sure, the context will exist, when
> the [func] is called.
>
> *Inclusion?*
>
> Perhaps the Qooxdoo developers want to add this behavior to *
> qx.core.Object* by default?
> Usage of these methods, also in the framework code itself, would mean you
> don't have to manually clean up a lot of bindings and events all over the
> place, which should lead to less dispose-related bugs.
> It would prevent exactly the same sort of bug, i reported before about the
> form-controller (and which has already been fixed, with manual clean-up in
> the disposer)
>
> -- Greetings
> -- Ralf ( @ gong.nl )
>
> ============================================================================
>
>
> //////////////////////////////
> qx.Mixin.define("app.MHacks",{
> destruct:function(){
> //////////////////////////////
>
>   if( this.__remoteBindings ){
>     this.__remoteBindings.forEach( function( vMap ){
>       vMap.target.removeBinding( vMap.id );
>     });
>     this.__remoteBindings = null
>   }
>
>   if( this.__remoteListeners ){
>     this.__remoteListeners.forEach( function( vMap ){
>       vMap.target.removeListenerById( vMap.id );
>     });
>     this.__remoteListeners = null;
>   }
>
> ///////////
> },members:{
> ///////////
>
>   addBindingTo:function( vSource, vSourceProp, vTarget, vTargetProp, vMap
> ){
>     if( !this.__remoteBindings ) this.__remoteBindings = [];
>     var vBindId = vSource.bind( vSourceProp, vTarget, vTargetProp, vMap );
>     this.__remoteBindings.push( {bindId: vBindId, target: vSource} )
>     return vBindId;
>   },
>
>   addListenerTo:function( vTarget, vEvent, vFunc, vContext ){
>     if( !this.__remoteListeners ) this.__remoteListeners = [];
>     var vListenerId = vTarget.addListener( vEvent, vFunc, vContext ?
> vContext : this );
>     this.__remoteListeners.push( {listenerId: vListenerId, target: vTarget}
> );
>   },
>
>   addListenerOnceTo:function( vTarget, vEvent, vFunc, vContext ){
>     if( !this.__remoteListeners ) this.__remoteListeners = [];
>     var vListenerId = vTarget.addListenerOnce( vEvent, vFunc, vContext ?
> vContext : this );
>     this.__remoteListeners.push( {listenerId: vListenerId, target: vTarget}
> );
>   }
>
> ////
> }});
> ////
>
>  <ATT00001..txt><ATT00002..txt>
>
>
>
>
> ------------------------------------------------------------------------------
> The Palm PDK Hot Apps Program offers developers who use the
> Plug-In Development Kit to bring their C/C++ apps to Palm for a share
> of $1 Million in cash or HP Products. Visit us here for more details:
> http://p.sf.net/sfu/dev2dev-palm
> _______________________________________________
> qooxdoo-devel mailing list
> qooxdoo-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to