PDA

View Full Version : [SOLVED] Observable addEvents(), Observable relayEvents() Questions



msinn
23 Dec 2010, 3:10 AM
Hello everybody,

please help me to better understand the public methods addEvents() and relayEvents() of the class Observable:

1.



addEvents( Object|String o, string Optional. ) : void

Adds the specified events to the list of events which this Observable may fire.
Parameters:

* o : Object|String
Either an object with event names as properties with a value of true or the first event name string if multiple event names are being passed as separate parameters.
* Optional. : string
Event name if multiple event names are being passed as separate parameters. Usage:

this.addEvents('storeloaded', 'storecleared');

Returns:

* void

1.a Does it mean, that when I pass an Object as


this.addEvents({
"fired" : true,
"quit" : true
});the second argument has NO application here?

1.b Does it mean, that when I pass a String as


this.addEvents('fired');the passed event will be assigned the true value and when I pass it so:


this.addEvents('fired', 'quit');is actually the same as in 1.a ?? What does it mean this statement: 'or the first event name string if multiple event names are being passed as separate parameters'
multiple events mean actually just 2 events ?? or I'm wrong?

2. This is maybe a pointless question, but is that right, that this Object, which relays the events from the passed Observable, must have those events added and defined listeners for them?




relayEvents( Object o, Array events ) : void

Relays selected events from the specified Observable as if the events were fired by this.

Parameters:

* o : Object
The Observable whose events this object is to relay.
* events : Array
Array of event names to relay.

Returns:

* void

Again, Thank You!

Condor
23 Dec 2010, 4:32 AM
1. addEvents({'x': true, 'y': true}) and addEvents('x', 'y') are equivalent.

2. relayEvents will automatically addEvents, so you don't have to do that yourself. Registering listeners is completely optional.

msinn
23 Dec 2010, 5:30 AM
1. addEvents({'x': true, 'y': true}) and addEvents('x', 'y') are equivalent.

2. relayEvents will automatically addEvents, so you don't have to do that yourself. Registering listeners is completely optional.

Thank You again Condor !

I can also do addEvents('x', 'y', 'z',...). The source code shows me that too, but sometimes I'm just blind :)



addEvents : function(o){
var me = this;
me.events = me.events || {};
if (typeof o == 'string') {
var a = arguments,
i = a.length;
while(i--) {
me.events[a[i]] = me.events[a[i]] || TRUE;
}
} else {
Ext.applyIf(me.events, o);
}
},