Robotlegs beginner Q&A

Here’s a list of a few questions a Robotlegs beginner might have, provided with answers. You would probably find all these answers if you read the Best Practices doc (which i strongly encourage! ) , but this is intended for quick lookup. Currently it’s only a small list and does not cover all the problems a beginner might stumble upon but I’ll keep updating it. Any tips or requests are also welcome. And of course you can always check out the Knowledge Base and the Google Groups for more information.
Here we start :
1. Is the Robotlegs MVCS base implementation the correct way to implement robotlegs in my application?
2.Can I use Robotlegs in Flash IDE ?
3.Which is the default IoC /DI solution in Robotlegs ?
4.I don’t like SwiftSuspenders or I have my own DI/IoC library I want to use. Is that possible?
5.How do I use injections in RL?
6.Do I have to map all my injections in the Context class ?
8. If I want to write my own Injector class , is there any guidline I have to follow ?
10. What is the difference between mapSingleton and mapSingletonOf ?
11. Ok, I mapped a mediator to a view Class. Now when is my mediator Class being created?
12. What does the “oneshot” parameter of the mapEvent method means ?
13. Can I develop modular applications using Robotlegs?
14. What are the functions performed by the Context in a Robotlegs application ?
19. Does Robotlegs support event bubbling?
20. Events can be received by both mediators and commands. How do I know which one is better?
21. Can I instantiate or call a command from other framework classes ?
22. How can I access the event that was triggered from the command ?
23. Can I call a command from another command?
24. Can I access a view component from the mediator it was mapped to?
25.How do I listen to framework events in a mediator?
27. Why do I have to use the mapListener rather than using the standard addEventListener ?
28. Can I access another Mediator from my Mediator class?
29. Can I listen for framework events in the Model or Service class?
30. Why is it encouraged to implement an Interface for the Service and/or Model class?
31. Can I pass VO data through events ?
32. Do I have to use the ContextEvent in my application?
Answer: The base implementation that Robotlegs comes with is just an example, a reference to help developers jump start to using the framework. It does follow best practices and you can use as much as you want from it. Of course you can define your own implementation of the framework to suit your needs.
Answer: Sure. Robotlegs uses the [Inject] meta to perform injections and for that you need the mxmlc compiler. To use the Flash IDE you need to define your injections using XML. Here’s a basic example : http://www.helmutgranda.com/2009/12/02/robotlegs-and-flash-ide-cs4-injection/
Update : I got this tip from Max Nylin that in Flash CS5, you can check the Publish ‘Settings > Flash > Export SWC’ setting and Robotlegs will work without defining the XML to the injector.
Answer: Robotlegs makes use of the SwiftSuspenders framework for IoC.
Answer: Of course, you can implement your own injection framework and use that inside of Robotlegs.
Answer: First, you have to map your class so that the injector knows what you want to inject. Than you can simply use the [Inject] metadata wherever you want to perform the injection. There is a second way of achieve this and that is of manually performing the injections.
Answer: No. You can map injections in all the classes that contain the Injector.
Answer: Well, injection is indeed performed by the Injector. Both the mediatorMap and the commandMap are making use of the Injector as well, though they are both equipped with additional functionality to help these tiers (Mediators and Commands).
Answer: Yes, if you want the same functionality as the default Injector in Robotlegs , you must implement the IInjector interface.
Answer: Well, first off, the “singletons are bad” debate is probably a never-ending discussions. There are pros and cons, so let’s not get into that right now. Secondly, the mapSingleton method in Robotlegs provides a single instance of the class to be used in all injections. This instance is not a Singleton enforced by the class itseslf, but rather an instance provided by the framework.
Answer: mapSingletonOf is used for mapping interfaces or abstract classes. It also requires you to pass an interface or an abstract class. mapSingleton is used for concrete implementations.
Answer: The mediator class is created when your view class is added to the stage. At that point the onRegister function of the Mediator class is being called.
Answer: If set to true, the command will execute only one time and then be unmapped. That means that if the same event triggers again the command will no longer execute. If set to false (the default is false) than the command will execute each time the event is triggered.
Answer: Yes, but be aware that each module must have it’s own Context.
Answer: The main function performed by a Context is to provide the central event bus as well as to initialize and de-initialize your application.
Answer: It is true that the tiers can only communicate with their respective Context but you can communicate from one Context to another.
Answer: Yes. While it is true that Robotles is build using the native flash event system, you can modify the framework to use your own system.
Answer: Well, you can use only one class to perform both duties but that is not intended as best practices. The Model and Service class do both implement the same Actor class but the separation is because of the different functionality that the 2 tiers have in an application.
Answer: No. Robotlegs promotes decoupling of tiers so you should very easily refactor your classes to suit other needs. For example View, Model, Service and VO classes are intended to be highly portable.
Answer: No. Because Robotlegs uses the Context as the main even buss and does not rely on the flash display list you cannot use event bubbling.
Answer: Well, as a best practice advice I advice that you capture events that require to perform work directly on a view component in the Mediator and let the other events trigger a Command.
Answer: No. A Command is instantiated by the framework and called in response the framework event it was mapped to. You should never attempt to instantiate or make a direct call to a Command from another class.
Answer: You can inject the event into the Command using the [Inject] metadata and have access to it.
Answer: Yes, Commands also dispatch events so you can dispatch a new event that has been mapped to another Command.
Answer: Yes, just like with Commands (see 22) you can inject the view component in the Mediator and access it.
Answer: You can use the eventDispatcher property that is injected into every framework actor at instantiation.
Answer: Well it’s a little tricky but Elad Elrom has implemented a great example using the Presentation Model : http://elromdesign.com/blog/2010/01/23/robotlegs-presentation-model-access-entire-component-events-lifecycle/
Answer: The mapListener is a method of the EventMap which makes sure each event is removed when the mediator is no longer used by the framework. This ensures the classes are collected by the Garbage Collector and are no longer used by the Flash Player. You can use the standard way but you have to manually remove the events.
Answer: Yes, you can inject a Mediator class in another Mediator class though it is highly discouraged and considered bad practice.
Answer: Yes you can, but you shouldn’t.
Answer: I strongly encourage to implement an Interface in your Service and/or Model class and use that interface in all your injections instead of the concrete class because it promotes decoupling and helps you better unit test your application. By doing so you can easily swap service and/or model classes at runtime.
Answer: Yes. Because you can inject the event and access it’s properties, you can easily pass data from tier to tier through events.
Answer: No, you don’t. They are there to help you bootstrap your application fast but that doesn’t mean you have to use them.
Answer: Simple. You can map a single instance of your class for all injections using the mapSingleton method and then inject it whenever your need to access it’s properties.
This entry was posted on Thursday, February 18th, 2010 at 1:29 pm and is filed under ActionScript, robotlegs. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.