Mediator listens for Signal from View
hi,
I'm a bit baffled why I cannot seem to make a mediator listen
for a Signal
dispatched from a view. They are mapped in my application
context.
I was hoping I could just create a new regular signal in the
view:
public var mySignal:Signal = new Signal();
and then, when something happens (dynamically, not a mouse
event), dispatch it
mySignal.dispatch(parameter);
and listen for it in the mediator (in which I inject the view)
in the onRegister method:
view.mySignal.add(onSomethingHappened);
but the onSomethingHappened method is not being triggered.
Should this be possible? If not, what is the simples way of
dispatching a (non mouse) event
from a view and make a mediator listen for it?
Btw, for mouse events I'm always using NativeSignal, which works fine..
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Stray on 04 Sep, 2011 03:08 PM
Hi Jeff,
First of all - it's best to use SignalMediator as this will give you automatic clean up of handlers added to Signals when your view leaves the stage and your mediator is destroyed. You can find it on github here:
https://github.com/Stray/robotlegs-utilities-SignalMediator
There's no reason though why the code you've given shouldn't work - if you want to post your actual code that's might be useful. Have you checked that onRegister is actually running (with a trace)? Sometimes race conditions mean that the view is on stage before the mediator is mapped, in which case the mediator won't be created.
hth,
Stray
2 Posted by JeffW. on 04 Sep, 2011 03:24 PM
true, Stray, i just noticed the mediator is not being registered.
As said, I'm mapping the two in my application context,
but I'm creating the view somewhere later, not right away.
Could that be the reason?
How can I make sure that he mapping will work? Map them when the view is being added?
And where in my application should I do this?
Btw, I want to give a big compliment to you and some others here, who most of the time really fast!
3 Posted by Stray on 04 Sep, 2011 03:49 PM
Hi Jeff,
as long as the mediator mapping is created before the view is added, and as long as the view is added to the same stage that the contextView is on, then your mediator should be created automatically. Normally the mapping would be done in your context or in a bootstrapper (a command that you run from your context to do wiring jobs).
There are some known issues with early versions of FP9, but otherwise it should be that simple.
The mediator section of the common problems wiki might help: https://github.com/robotlegs/robotlegs-framework/wiki/common-problems#wiki-mediator-not-running-onregister
But really it only repeats what I've just said - and usually you would only have problems if your view hits the stage *before* the mapping is made - late arriving views shouldn't cause problems.
Do you have other views being mediated in this app? Are their mediators working ok?
Thanks for the compliment :)
Stray
4 Posted by JeffW. on 04 Sep, 2011 04:14 PM
yes, I have lots of mediators/views, they all work fine.
Maybe the problem is caused by my view having a subview (extending the view), which has its own mediator; is that bad practice by any chance? Luckily, it seems that I can use the subview for what I want to achieve, but I'm confused about the problem.
5 Posted by Stray on 04 Sep, 2011 05:14 PM
Hi Jeff,
I'm not 100% clear what you're describing - but basically the mapping has to be for the exact concrete class that will land on the stage - for performance reasons Robotlegs doesn't check against interfaces or superclasses when matching views to their mappings.
Stray
Support Staff 6 Posted by Ondina D.F. on 02 Nov, 2011 04:02 PM
Hi Jeff,
Feel free to re-open this discussion in case you have more questions or you need further assistance with this issue. Please open new threads for new issues.
Thank you for posting
Ondina
Ondina D.F. closed this discussion on 02 Nov, 2011 04:02 PM.