Currently using robotlegs-utilities-Modular but moving to RL2 how to achieve a commandMap, moduleCommandMap
Being exposed to the event dispatcher for the context and module seperatly is what i would like to achieve.
I have looked at this example https://github.com/MBarjawi/robotlegs2-ModularCommunications which is great when defining seperate eventDispatchers for global and moduleOnly modes, but how do i then inject these into a commandMap:ICommandMap and moduleCommandMap:ICommandMap.
Can someone please help.
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 Sharif El-Borgi on 15 Oct, 2012 12:39 PM
... to add what i want to be able to achieve is the same as i had before, which was to be able to dispatch an event within and context and to the other modules and not the context im dispatching from.
Thanks,
Sharif
Support Staff 2 Posted by Ondina D.F. on 15 Oct, 2012 01:53 PM
Hello Sharif,
From my experience, you can define the “channels” (dispatchers) in the parent context of 3 sibling modules like this:
context.extend(new ScopedEventDispatcherExtension("global", "channelOne", "channelTwo"));
[Inject(name="global")] public var globalDispatcher:IEventDispatcher;
you’ll have to disptach the events like this:
globalDispatcher.dispatchEvent(new SomePopUpEvent(SomeEvent.SOMETHING_HAPPENED));
and the shell and modules would listen to the event like this:
eventMap.mapListener(globalDispatcher, SomeEvent.SOMETHING_HAPPENED, onSomethingHappened, SomeEvent);
If one of the Modules is not interested in sharing the “global” dispatcher, it won’t inject it in the first place, or it won’t listen for that event on this dispatcher.
Also look at the settings of the ModularityExtension. Here a discussion about the different settings and their consequences for the modules: http://knowledge.robotlegs.org/discussions/robotlegs-2/68-modular-a...
add a listener:
eventMap.mapListener(someDispatcher, SomeEvent.SOMETHING_HAPPENED, onSomethingHappened, SomeEvent);
and dispatch the event:
someDispatcher.dispatchEvent(new SomeEvent(SomeEvent.SOMETHING_HAPPENED));
In Mediators like this:
addContextListener(SomeEvent.SOMETHING_HAPPENED, onSomethingHappened, SomeEvent);
dispatch(new SomeEvent(SomeEvent.SOMETHING_HAPPENED));
In commands you’d have to inject the dispatcher:
[Inject] public var localDispatcher:IEventDispatcher;
localDispatcher.dispatchEvent(new SomeEvent(SomeEvent.SOMETHING_HAPPENED));
I hope I understood your question correctly.
Ondina
3 Posted by Sharif El-Borgi on 15 Oct, 2012 02:01 PM
Thank you for the prompt reply. I gathered i could do as you explained, what i was looking for was previously in RL1 you could use commandMap.map.... and moduleCommandMap .... to achieve this, do i create a new instance of IEventCommandMap (i.e var commandMap = new EventCommandMap(globalDispatcher) and var moduleCommandMap = new EventCommandMap(moduleChannelDispatcher) ) then pop them into the injector of the context? if so how do i then pass these into each context? using the ModularityExtension - i guess i would like to use the EventCommandMap as a wrapper for manageing mapping and unmapping events to Commands.
Sharif
Support Staff 4 Posted by Ondina D.F. on 15 Oct, 2012 02:24 PM
No problem.
Hehe, it seems I misunderstood your question though.
Let’s see if I get it right this time.
I guess you want to dispatch an event from a module to trigger a command mapped in the shell’s context?
I’m not sure about the best solution in this case. I hope Shaun or Stray will answer this.
I only can tell you how I solved such a situation:
In the Shell’s context:
commandMap.map(SomePopUpEvent.OPEN_POPUP, SomePopUpEvent).toCommand(SomePopUpCommand);
In the Module’s Context:
parentDispatcher=injector.parentInjector.getInstance(IEventDispatcher);
injector.map(IEventDispatcher, "somePopUpDispatcher").toValue(parentDispatcher);
In the class that wants to open the shell’s popup:
[Inject(name="somePopUpDispatcher")] public var somePopUpDispatcher:IEventDispatcher;
somePopUpDispatcher.dispatchEvent(new SomePopUpEvent (SomePopUpEvent.OPEN_POPUP));
5 Posted by Sharif El-Borgi on 15 Oct, 2012 02:30 PM
Yeah that sounds like a midterm solution - i think i will go with that for time being, hopefully Shaun or Stray can shed some light here.
6 Posted by Sharif El-Borgi on 15 Oct, 2012 02:31 PM
oh! and thank you! :) much appreciated Ondina!
7 Posted by Sharif El-Borgi on 15 Oct, 2012 02:35 PM
Thanks Ondina!
Support Staff 8 Posted by Ondina D.F. on 15 Oct, 2012 02:39 PM
I wasn't of much help, but, of course, you're welcome, Sharif:)
9 Posted by Sharif El-Borgi on 15 Oct, 2012 02:49 PM
Just had a thought.... I could get the EventCommandMap from the parentInjector right?
that way i can use it in the Modules too to map events from other modules :)
or am i way off?
Support Staff 10 Posted by Ondina D.F. on 15 Oct, 2012 02:56 PM
I think you can do that. Try it out and see if it's what you really want:)
And don't forget to report back.
Support Staff 11 Posted by Ondina D.F. on 15 Oct, 2012 06:03 PM
My findings:
Shell Context:
shellDispatcher=injector.getInstance(IEventDispatcher);
injector.map(IEventDispatcher, "hello").toValue(shellDispatcher);
[1]module’s command mapped in shell’s context
//shellCommandMap.map(SomeEvent.TRIGGER_MODULE_COMMAND, SomeEvent).toCommand(ModuleCommand);
[2] shellCommandMap.map(SomeEvent.TRIGGER_SHELL_COMMAND, SomeEvent).toCommand(ShellCommand);
In a Class
[Inject(name="hello")] public var helloDispatcher:IEventDispatcher;
//this triggers the Module’s command:
helloDispatcher.dispatchEvent(new SomeEvent (SomeEvent.TRIGGER_MODULE_COMMAND));
Module Context:
var parentCommandMap:IEventCommandMap=injector.parentInjector.getInstance(IEventCommandMap);
[1] module’s command mapped in module’s context, using shell’s commandmap
parentCommandMap.map(SomeEvent.TRIGGER_MODULE_COMMAND, SomeEvent).toCommand(ModuleCommand);
In a Class:
[Inject(name="hello")] public var helloDispatcher:IEventDispatcher;
//triggers Shell’s command:
helloDispatcher.dispatchEvent(new SomeEvent(SomeEvent.TRIGGER_SHELL_COMMAND));
Till tomorrow...
12 Posted by Sharif El-Borgi on 17 Oct, 2012 10:34 AM
Hi Ondina,
Im still having trouble with the modules having there own eventDispatcher. So currently im dispatching an event from within a module, this is getting picked up by the Shell commandMap ... where as i would like to keep this in the module.
Steps i would like:
whats happening :
in this example i have used a common event.
Not sure why this is happening? and not sure how to seperate the two.
ive added link to github for this project https://github.com/iamsharife/RL2Example
Sharif
Support Staff 13 Posted by Ondina D.F. on 17 Oct, 2012 10:37 AM
Hi Sharif,
I'll take a look at your example and come back with answers (or questions).
Ondina
Support Staff 14 Posted by Ondina D.F. on 17 Oct, 2012 11:50 AM
I tried out your example, and made these modifications:
ApplicationConfig
BlogModel
BlogViewMediator
In MainMediator do the same as in BlogViewMediator, and in ApplicationModel the same as in BlogModel.
ChangeLabelEvent
With these modifications, when BlogModel or ApplicationModel dispatch ChangeLabelEvent, both, BlogViewMediator and MainMediator, react to the event and the payload is the value set in the model dispatching the event.
Not sure, if that’s what you want, though. If it’s not what you wanted, please explain again using the names of the classes, so I can follow better.
15 Posted by Sharif El-Borgi on 17 Oct, 2012 12:01 PM
This is very helpful. However, im trying to really make use of the CommandMap again like in RL1. So i have a command in the Shell and a command in the Blog Module. I then would like to have a command map for each of these contexts. each responding to there own events. So when the event is dispatched via its eventDispatcher in its context, it is reacted to by the correct command map.
Support Staff 16 Posted by Ondina D.F. on 17 Oct, 2012 12:13 PM
dispatch(new ChangeLabelEvent(ChangeLabelEvent.CHANGE_LABEL_REQUEST));
Actually, it gets picked up by the BlogChangeLabelCommand. Use traces or log to see it.
Actually, it updates BlogModel.
Nope, it is the one from BlogModel, but I found the culprit:
You are injecting ApplicationModel into BlogMediator
[Inject] public var model:ApplicationModel;
You surely want BlogModel instead, right?
Inject BlogModel, and it will work as you wanted it to work:) No other modifications are needed.
17 Posted by Sharif El-Borgi on 17 Oct, 2012 01:41 PM
Thank you! thats great. Let me go back to the example app and check this further. Thanks again for your prompt reply.
Support Staff 18 Posted by Ondina D.F. on 17 Oct, 2012 04:58 PM
My pleasure!
Ondina D.F. closed this discussion on 23 Oct, 2012 10:44 AM.