many view inject in mediator

transglobals's Avatar

transglobals

16 Jan, 2014 12:21 PM

is possible in mediator using many inject displayobject in RL2?
example
...

public class RealCaseMediator extends Mediator{
    [Inject]
    public var view1:Mc1;
    [Inject]
    public var view2:Mc2;
...

and using for him hitTestObject

im now get error: Injector is missing a mapping to handle injection into property...

  1. Support Staff 1 Posted by Ondina D.F. on 16 Jan, 2014 02:00 PM

    Ondina D.F.'s Avatar

    If you mapped a view like this:

    mediatorMap.map(RealCaseView).toMediator(RealCaseMediator);
    

    When RealCaseView is added to the stage, RealCaseMediator will be created.
    RealCaseView will be injected into RealCaseMediator, if you do this:

    public class RealCaseMediator extends Mediator
    {
        [Inject]
        public var view:RealCaseView;
    ...
    

    If you want Mc1 and Mc2 to be injected into RealCaseMediator in addition to RealCaseView, you must provide mappings for Mc1 and Mc2. Without mappings, the injector has no idea what to do.

    injector.map(Mc1).asSingleton();
    injector.map(Mc2).asSingleton();
    mediatorMap.map(RealCaseView).toMediator(RealCaseMediator);
    

    and in your Mediator:

    public class RealCaseMediator extends Mediator
    {
        [Inject]
        public var realCaseView:RealCaseView;
    
        [Inject]
        public var view1:Mc1;
    
        [Inject]
        public var view2:Mc2;
    
    ...
    

    Also, see my answers here:
    http://knowledge.robotlegs.org/discussions/robotlegs-2/5766-automag...
    http://knowledge.robotlegs.org/discussions/robotlegs-2/8018-why-i-c...

    Do you really need to inject Mc1 and Mc2 into RealCaseMediator? Maybe you just need to add them to RealCaseView inside the view, and dispatch a custom event from RealCaseView when Mc1 or Mc2 gets hit. RealCaseMediator should add a listener for that custom event coming from the view.

    Ondina

  2. 2 Posted by transglobals on 16 Jan, 2014 02:10 PM

    transglobals's Avatar

    thanks:) i'm have little chaos with some principe of the RL:)

    problem with hitTestObject i'm solved using custom event that contain "Mc2"

  3. transglobals closed this discussion on 16 Jan, 2014 02:10 PM.

  4. transglobals re-opened this discussion on 17 Jan, 2014 11:08 AM

  5. 3 Posted by transglobals on 17 Jan, 2014 11:08 AM

    transglobals's Avatar

    hm, i'm have still problem.
    Is possible in-mediator work with many mediate displayobjects?

    [Inject] other mediator not work

    [Inject] displayobject where is mediated not vork

  6. Support Staff 4 Posted by Ondina D.F. on 17 Jan, 2014 01:15 PM

    Ondina D.F.'s Avatar

    Hi,

    If you have a mediator like this one:

    public class SimpleMediator extends Mediator
    {       
        [Inject]
        public var view:SimpleView;
            
        override public function initialize():void
        {
    ...etc
    

    and another Mediator like this one:

    public class SomeMediator extends Mediator
    {       
        [Inject]
        public var view:SomeView;
    
        [Inject]
        public var simpleView:SimpleView;
            
        override public function initialize():void
        {
            view.addElement(simpleView);
        }
    

    If you map your views with the mediatorMap like this:

    mediatorMap.map(SimpleView).toMediator(SimpleMediator);
    mediatorMap.map(SomeView).toMediator(SomeMediator);
    

    SimpleView will be injected only into SimpleMediator, but not into SomeMediator.

    If you map SimpleView like this:

    injector.map(SimpleView).asSingleton();
    mediatorMap.map(SimpleView).toMediator(SimpleMediator);
    
    mediatorMap.map(SomeView).toMediator(SomeMediator);
    

    and you try to inject SimpleView into SomeMediator, SimpleView will be injected into SomeMediator, but the injector will complain about overriding the mappings for SimpleView, when it tries to satisfy the rule defined with mediatorMap.map(SimpleView).toMediator(SimpleMediator);.
    You could unmap SimpleView and then re-map it with the mediatorMap, but that would be really cumbersome.
    To avoid unmapping SimpleView and re-mapping it again, you could use the viewProcessorMap instead of the mediatorMap to create a mediator for SimpleView:

    injector.map(SimpleView).asSingleton();
    
    ///here, use viewProcessorMap to create a mediator for SimpleView:
    viewProcessorMap.map(SimpleView).toProcess(new MediatorCreator(SimpleMediator));
    
    mediatorMap.map(SomeView).toMediator(SomeMediator);
    

    Even though you can use the trick with the viewProcessorMap, I still think that you should let a View handle the process of adding and removing child-views, instead of the Mediator.
    Why do you need to inject the child-views into the mediator of the parent-view? Maybe you are overcomplicating things :) There might be a much easier solution to you problem, but you have to say more about your use case.

    i'm have little chaos with some principe of the RL:)

    You'll have to read more about how injection works:) I've given you some links in my previous post. Read them again. And these ones, in case you did not find them until now:

    https://github.com/robotlegs/robotlegs-framework/wiki/Robotlegs-Int...
    https://github.com/robotlegs/robotlegs-framework/wiki/Best-Practices

    Look at examples and other discussions on this forum.
    I know, it is not easy to understand all the robotlegs concepts at once, especially if you were using other frameworks before. But, I can assure you, that robotlegs and dependency injection are a lot easier than they seem in the beginning! There are some tutorials and examples for robotlegs 1 that could help you understand the principles, which are the same in both versions of the framework. If you can't find them, I can give you the urls.

    Ondina

  7. 5 Posted by transglobals on 17 Jan, 2014 02:22 PM

    transglobals's Avatar

    thanks:)

    pity that links is not for RL2

  8. transglobals closed this discussion on 20 Jan, 2014 05:37 PM.

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