RL2 modularity example

62 views
Skip to first unread message

Adnan Doric

unread,
Feb 7, 2012, 2:33:55 PM2/7/12
to robo...@googlegroups.com
Hello group :)

Can anyone please provide a simple how-to for cross-context
communication with RL2?

I see ScopedEventDispatcherExtension and
ScopedMessageDispatcherExtension but have difficulties figuring out how
to use them properly to enable parentContext -> childContext communication.

Thank you in advance,
Adnan

Neil Manuell

unread,
Feb 7, 2012, 3:02:09 PM2/7/12
to robo...@googlegroups.com
would this help at all?



--
You received this message because you are subscribed to the Google
Groups "Robotlegs" group.
To post to this group, send email to robo...@googlegroups.com
To unsubscribe from this group, send email to
robotlegs+unsubscribe@googlegroups.com
for support visit http://knowledge.robotlegs.org

Shaun Smith

unread,
Feb 7, 2012, 3:26:17 PM2/7/12
to robo...@googlegroups.com
Hi Adnan,

The ScopedEventDispatcherExtension is probably what you need. If you add that extension to both the parent and the child contexts, then you can inject a shared dispatcher wherever you need it:

[Inject(name="global")]
public var dispatcher:IEventDispatcher;

This assumes that you installed the extension into both contexts in the default way (as a class):

_context = new Context(
ClassicRobotlegsBundle,
ScopedEventDispatcherExtension,
someView);

By default a shared dispatcher named "global" will be installed.

If you want more than one shared dispatcher, or you want to alter how things are named and shared you can provide an instance of the extension with constructor arguments:

_parentContext = new Context(
ClassicRobotlegsBundle,
new ScopedEventDispatcherExtension("bus1", "bus2"),
parentView);

_childContext = new Context(
ClassicRobotlegsBundle,
new ScopedEventDispatcherExtension("bus1", "bus2", "bus3"),
childView);

_grandChild = new Context(
ClassicRobotlegsBundle,
new ScopedEventDispatcherExtension("bus3"),
grandChildView);

When a named dispatcher has been mapped into a parent, that mapping is inherited by children. When the parent does't have a mapping the child creates its own mapping (that can be inherited by its children etc).

So, looking at the setup above, we can see that the parent will share "bus1" and "bus2" which the child will inherit. The parent won't have access to "bus3", but the grand-child will.

The extension is actually much more simple than it sounds, have a look a the source:


Hope that makes sense! Please let me know how it goes.

p.s. The ScopedMessageDispatcherExtensions works in exactly the same way, but it shares IMessageDispatchers instead of IEventDispatchers.

--
You received this message because you are subscribed to the Google
Groups "Robotlegs" group.
To post to this group, send email to robo...@googlegroups.com
To unsubscribe from this group, send email to

Adnan Doric

unread,
Feb 8, 2012, 3:11:22 AM2/8/12
to robo...@googlegroups.com
Thank you Shaun, that was exactly the information I was looking (global or restricted) and it works perfectly for the moment :)

Also thanks to Neil for trying to help !
Cheers
I see ScopedEventDispatcherExtension and ScopedMessageDispatcherExtension but have difficulties figuring out9 how to use them properly to enable parentContext -> childContext communication.


Thank you in advance,
Adnan

--
You received this message because you are subscribed to the Google
Groups "Robotlegs" group.
To post to this group, send email to robo...@googlegroups.com
To unsubscribe from this group, send email to
robotlegs+...@googlegroups.com
for support visit http://knowledge.robotlegs.org

Neil Manuell

unread,
Feb 8, 2012, 4:40:54 AM2/8/12
to robo...@googlegroups.com
trying... thats me :-/

Adnan Doric

unread,
Feb 8, 2012, 11:41:30 AM2/8/12
to robo...@googlegroups.com
Hey Neil !
I see that you are eager to help so I spent all day trying to find a question for you!

Here it goes:
How to mark a view for injection knowing there is no ViewMap in RL2?

I see a discussion here, but I see no trace of it in GitHub:
https://github.com/robotlegs/robotlegs-framework/issues/34

Thank you for helping :)
Adnan

Shaun Smith

unread,
Feb 14, 2012, 11:37:11 AM2/14/12
to robo...@googlegroups.com
Unfortunately there's no ViewMap yet. We'll tackle that soon.

Alex

unread,
Feb 14, 2012, 4:26:01 PM2/14/12
to Robotlegs AS3
Hi guys.
Can some one show a working example? Because all my tries to dispatch
events between context are failed.

ScopedEventDispatcherExtension is installed into both contexts.

public class ModuleMediator extends Mediator {

[Inject(name="global")]
public var dispatcher:IEventDispatcher;

private function onTestButtonClick(event:MouseEvent):void {
dispatcher.dispatchEvent(new Event( "test" ));
}
}


public class AppMediator extends Mediator {

[Inject(name="global")]
public var dispatcher:IEventDispatcher;

override public function initialize():void {
dispatcher.addEventListener("test", testListener);
}

private function testListener(event:Event):void {
trace("Aliluya");
}

}
Reply all
Reply to author
Forward
0 new messages