injectViewAs in RL2

Ruben's Avatar

Ruben

08 Aug, 2017 05:13 PM

Hello,

we are currently trying to migrate from RL1 to RL2 to evaluate a possible Haxe port of our games.

In RL1 we make extensive use of injectViewAs, for example: mediatorMap.mapView(BuyPopup, BuyPopupMediator, IPopup);

This allows us to have BuyPopupMediator extend BasePopupMediator that handles all basic Popup code. The view is injected into BasePopupMediator as IPopup.

What is the equivalent in RL2 to inject a view as a specific subclass in the mediator? There seems to be no injectViewAs functionality. Currently, we are mapping our mediators like this:

mediatorMap.map(BuyPopup).toMediator(BuyPopupMediator);

This fails, because BuyPopupMediator tries to inject an instance of IPopup.

Thanks in advance,
Ruben

  1. Support Staff 1 Posted by Ondina D.F. on 10 Aug, 2017 06:46 AM

    Ondina D.F.'s Avatar

    Hello Ruben,

    mediatorMap.mapMatcher:

    mediatorMap
    .mapMatcher(new TypeMatcher()
    .allOf(IBaseView, ISubView, SomeView))
    .toMediator(SomeMediator);
    
    mediatorMap
    .mapMatcher(new TypeMatcher()
    .allOf(IBaseView, IAnotherSubView, AnotherView))
    .toMediator(AnotherMediator);
    

    Please take a look at these answers:

    http://knowledge.robotlegs.org/discussions/robotlegs-2/17748-differ...

    http://knowledge.robotlegs.org/discussions/robotlegs-2/3714-mediati...

    robotlegs documentation on github:

    https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...

    Let me know whether it's what you are looking for or not.
    Ondina

  2. 2 Posted by Ruben on 10 Aug, 2017 10:12 AM

    Ruben's Avatar

    Hi Ondina,

    thanks for your swift response! This seems to work quite well, thank you. However I have one problem now: In Robotlegs 1 we were doing this:

    mediatorMap.mapView(BuyPopup, BuyPopupMediator, IPopup);
    //... some other specific Popup / Mediator combinations
    mediatorMap.mapView(IPopup, BasePopupMediator);
    

    In Robotlegs 1 this results in all Popups having exactly one Mediator. Only popups that would not have a hit against one of the specific combinations would receive a BasePopupMediator. (Note we were using an InterfaceMediatorMap I found online somwhere). So every popup ends up with exactly one Mediator. Only popups that dont have their specific mediator defined will receive a BasePopup Mediator.

    I am now trying to recreate the behavior in Robotlegs 2 like this:

    mediatorMap.mapMatcher(new TypeMatcher().allOf(IPopup, LoginPopup)).toMediator(LoginPopupMediator);
    mediatorMap.map(IPopup).toMediator(BasePopupMediator);
    

    However Robotlegs 2 does not seem to stop when the first Mediator was created, so I end up with LoginPopup having 2 mediators: A LoginPopupMediator and a BasePopupMediator.

    Is there a way to make sure that only the first mediator is used? We have hundreds of specific popup classes, so using .noneOf() would seem overly complex and hard to maintain.

    Thanks in advance,
    Ruben

  3. Support Staff 3 Posted by Ondina D.F. on 10 Aug, 2017 03:41 PM

    Ondina D.F.'s Avatar

    No problem, Ruben.

    You shouldn't try to map the BasePopupMediator.

    I would create a derived class, let's say, DerivedPopupMediator, that would simply extend BasePopupMediator. It would be responsible for all IPopup views with the exception of LoginPopUp.

    mediatorMap
    .mapMatcher(
    new TypeMatcher()
    .allOf(IPopup) 
    .noneOf(LoginPopup))
    .toMediator(DerivedPopupMediator);
    
    mediatorMap
    .mapMatcher(new TypeMatcher()
    .allOf(IPopup, LoginPopup))
    .toMediator(LoginPopupMediator);
    

    Does this help?

  4. Support Staff 4 Posted by Ondina D.F. on 11 Aug, 2017 07:03 AM

    Ondina D.F.'s Avatar

    Maybe even better than the previous solution:

    Let all views that you don't want to be mediated by the DerivedPopupMediator implement yet another interface, a dummy interface, IExceptionView, without functionality. LoginPopup view would implement IPopup and IExceptionView.

    mediatorMap
    .mapMatcher(
    new TypeMatcher()
    .allOf(IPopup) 
    .noneOf(IExceptionView)
    )
    .toMediator(DerivedPopupMediator);
    
    mediatorMap
    .mapMatcher(new TypeMatcher()
    .allOf(IPopup, LoginPopup))
    .toMediator(LoginPopupMediator);
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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