PDA

View Full Version : Event Listeners



Bleak
26 Jan 2010, 9:26 AM
I understand that two different objects extending the observable interface are unable to listen to each others events, so what is the best way to allow 2 distinct components to listen to each others events?

The scenario, is that I have 2 components. The first is a table of projects the second is a component to create a new project. I want an event to fire when a new project is created such that the project table is automatically refreshed.

I'm not looking for source, just point me in the right direction or a description that this is even possible. I can do this by calling methods directly, but the concept will be a large part of the application I am writing so I'd like to understand my options first.

BTW: extJS is amazing.

Thank you.
Dean.

Animal
26 Jan 2010, 10:42 AM
I understand that two different objects extending the observable interface are unable to listen to each others events
Dean.



Why? You can add listeners to any Observable's event. It's just a function that gets called.

Bleak
26 Jan 2010, 11:36 AM
This is good news.. I thought I must be missing something.

Any chance you have some skeleton code that shows one object listening to another object's event?

26 Jan 2010, 11:49 AM
anyComponent.on('someEvent', this.handleThatEvent, this);

Bleak
26 Jan 2010, 12:01 PM
Awesome.. It seems to simple ;)

Appreciate the quick response, I'll give that a shot.

26 Jan 2010, 12:09 PM
the "this" reference is the scope for which you want the event handler to be called.