About best practic to Inject DisplayObject through Interface
Hi!
I have a Mediator and some view object:
this.mediatorMap.mapView(MainView, MainViewMediator);
In the Mediator constructor my code adds all childs of this DisplayObject to the display list:
public var background:Image = new Image(...);
public var counter:Counter = new Counter();
public var someObject:ISomeObject = new SomeObject();
public function MainView()
{
addChild(background);
addChild(counter);
addChild(someObject as DisplayObject);
}
My goal is control the ISomeObject in Context file, something like that:
this.injector.mapSingletonOf(ISomeObject, SomeObject);
It will be easy to choose what exactly DisplayObject I need at the moment, may be:
this.injector.mapSingletonOf(ISomeObject, SomeAnotherObject);
So to implement this idea I'm gonna to remove all code about ISomeObject from MainView and put it to MainViewMediator:
[Inject]
public var someObject:ISomeObject;
[Inject]
public var vo:MainView;
override public function onRegister():void
{
vo.addChild(someObject as DisplayObject);
}
Did not try it, but it should be ok.
The question is: This approach looks not good and may be here is more best practic than I suggested?
Thanks!
Valentin.
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 smival on 03 Dec, 2014 08:22 AM
ps - Robotlegs 1
pps - Of course here could be a lot of different Interfaces in this single MainViewMediator
Support Staff 2 Posted by Ondina D.F. on 03 Dec, 2014 05:10 PM
Hi Valentin,
Perhaps a view factory could be a better solution for your problem. See this discussion:
http://knowledge.robotlegs.org/discussions/questions/290-mediating-...
Ondina
3 Posted by smival on 11 Dec, 2014 09:29 AM
thanks a lot, I will learn it
Support Staff 4 Posted by Ondina D.F. on 17 Dec, 2014 02:56 PM
You're welcome!
Ondina D.F. closed this discussion on 17 Dec, 2014 02:56 PM.