Using injectAsView

Just a quick question regarding injectViewAs...

Is this intended to allow you to address multiple views with the same mediator?

For example if I have 20 buttons which implement the IButton Interface, if I injectViewAs IButton Interface will I be able to get to all my buttons with one mediator as they all impement the same interface?

I think I may be missing something here, any help is appreciated.

Thanks,

Scott

  1. Hi Scott,

    When a mediator is created a reference to the view that created it is temporarily mapped into the injector. By default that view instance is mapped by its concrete type, which allows us to do this in the mediator:

    [Inject]
    public var view:ConcreteViewType;
    

    The injectViewAs parameter allows the view instance to be mapped to a different type.

    // during mapping
    mediatorMap.mapView(MyView, MyMediator, SomeInterface);
    
    // in the mediator
    [Inject]
    public var view:SomeInterface;
    

    From RL v1.3.0 injectViewAs can accept an array of types. This can be handy when you have some kind of Abstract mediator (with an Injection point declared on it) that is extended into a more specialized mediator (with another injection point declared on it). Without the injectViewAs parameter injection into such a mediator would fail because one of the injection points could not be satisfied.

    Hope that makes some sense. I think I might have made it sound more complex than it is:

    http://github.com/robotlegs/robotlegs-framework/blob/v1.3.0/src/org...

  2. Hi Scott,

    Provided your [Inject] in the mediator is typed IButton then I believe what you're describing should work fine. (Assuming you're talking about one-mediator-per-view, but mapping the same mediator to each view?)

    the intent is to facilitate sub/superclasses in creating mediators.

    Take the case of BaseView and BaseViewMediator

    and then

    SpecialView and SpecialViewMediator

    in order to fulfil the injection in BaseViewMediator you need to 'inject SpecialView as' BaseView.

    The other thing worth knowing is that you can also pass an array as the injectViewAs parameter. This array would be all the classes you want this view injected as.

    So, if you did

    mediatorMap.mapView(SpecialView, SpecialViewMediator, [BaseView, SpecialView]);

    This would allow you to have this in your BaseViewMediator:

    [Inject]
    public var view:BaseView;

    and this in your SpecialViewMediator:

    [Inject]
    public var specialView:SpecialView;

    which means you can access SpecialView specific behaviour as well.

    Hopefully that answers your question - shout again if not,

    Stray

  3. Thanks for the replies, great answers.

    I think you've both covered it, just to clarify, if I have a sub class which I want to mediate I need to pass the base class into the InjectViewAs param to satisfy the injection?

    Scott

  4. Exactly!

    And if you want to reference the subClass too then pass both in an array.

  5. Makes total sense, thanks again for the help.

    I'll resolve this thread.

    Scott

  6. darloScottt closed this discussion on 06 Oct, 2010 07:57 AM.

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