Event Dispatching RL1 vs RL2
I am porting a test startup project from RL1 to RL2. Up till now everything went ok, but I am getting errors on my Event Dispatching lines.
In RL1 I used the following commands:
but in RL2 I had to change my code to include
public var eventDispatcher:IEventDispatcher;
and I have to change the code to:
Is this correct, because honestly, I find the documentation for RL2 confusing and incomplete.
Comments are currently closed for this discussion. You can start a new one.
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
1 Posted by ishaban.flash on 30 Sep, 2015 07:34 PM
afair it is correct solution make notification from commands, but i think in anyway it is better to dispatch event with properly type.
Support Staff 2 Posted by Ondina D.F. on 30 Sep, 2015 08:54 PM
I can't help you much at the moment, because I'm on holiday...
In addition to ishaban's answer just a short remark:
rl1 commands looked like so:
And an Actor class like this:
If you like the convenience classes from rl1, you can build your own command and actor base classes and use them with rl2.
3 Posted by roelof on 01 Oct, 2015 05:39 AM
Thanks for the reply, I will study the links that you provided Ondina and take it from there. I just wanted to make sure that I am on the right track, because there is still a lot I have to learn about AS3 / Flex / RL
Support Staff 4 Posted by Ondina D.F. on 08 Oct, 2015 03:09 PM
I'm back. Sorry for the delay.
The Command class in rl2 has been intentionally kept lightweight. All is needed for a Command to be recognized as such by rl2 is to expose a public method execute().
The rl1 Command had injections for the contextView, injector, mediatorMap, commandMap and eventDispatcher. Those came in handy, because we used to do the mappings inside of commands. With rl2 this is no longer necessary. You still can perform your mappings in commands, if you want. However, a class implementing IConfig is a much better way of structuring your mappings. You can inject whatever you need (and only what you need) into such a config class. This way they are much more lightweight. If you need help with config classes, let me know. Here just a link to a discussion about config classes:
So, as I said in my previous post, you can create a base class that contains the injections you need.
Just for having access to the shared event dispatcher and to be able to use the same syntax as with rl1, you can do this:
Then you can let your commands, models and services extend the SharedDispatcher.
If you want a rl2-command to behave exactly like a rl1-command:
In this case, your commands will have to extend the BaseCommand and to override the public function execute().
There is no need for a command extending the SharedDispatcher (give it a name of your choosing) to override execute()!
If you don't want to use base classes, you're right, you have to inject the event dispatcher into your commands as you did in your post. Or in a Model or Service for that matter.
Let me know if there is anything else you need help with while porting your project to rl2.
By the way, can you tell us why are you doing something like this:
I know that this works if you create the custom event class without a type argument, but mapping such an event to a command looks kind of weird with "" instead of a type ;)
So, I'm with ishaban on this, I prefer using meaningful event's types .
Ondina D.F. closed this discussion on 30 Nov, 2015 04:07 PM.