Inherited mediators mapping

Jono's Avatar

Jono

24 Oct, 2014 11:03 AM

Hi,

I'm looking to do exactly what is said here in the following post:

http://knowledge.robotlegs.org/discussions/robotlegs-2/11567-inheri...

But when I do it, I get:

Warning: Injector already has a mapping for xxx.view::BaseView|.
If you have overridden this mapping intentionally you can use "injector.unmap()" prior to your replacement mapping in order to avoid seeing this message. Exception fault: Error: Injector mapping override for type [class BaseView] with name

Any thoughts? Thanks.

  1. Support Staff 1 Posted by Ondina D.F. on 24 Oct, 2014 11:44 AM

    Ondina D.F.'s Avatar

    Hi Jono,

    can you paste the relevant code for your mappings?

  2. 2 Posted by Jono on 24 Oct, 2014 11:50 AM

    Jono's Avatar

    Hi Ondina,

    mediatorMap.mapMatcher(new TypeMatcher().allOf(BaseView, InterfaceView)).toMediator(InterfaceMediator);
    mediatorMap.mapMatcher(new TypeMatcher().allOf(BaseView, MainMenuView)).toMediator(MainMenuMediator);
    mediatorMap.mapMatcher(new TypeMatcher().allOf(BaseView, SideMenuView)).toMediator(SideMenuMediator);
    
  3. Support Staff 3 Posted by Ondina D.F. on 24 Oct, 2014 12:08 PM

    Ondina D.F.'s Avatar

    I can't see anything wrong with the mappings.
    Is it possible to attach your app or a simplified example reproducing the issue?

  4. 4 Posted by Jono on 24 Oct, 2014 12:15 PM

    Jono's Avatar

    Sure thing - will put an example together now. Thanks.

  5. 5 Posted by Jono on 24 Oct, 2014 12:31 PM

    Jono's Avatar

    Here is a simplified version of the issue. Thanks for having a look.

  6. Support Staff 6 Posted by Ondina D.F. on 24 Oct, 2014 12:35 PM

    Ondina D.F.'s Avatar

    ok I'll take a look and report back asap

  7. Support Staff 7 Posted by Ondina D.F. on 24 Oct, 2014 03:32 PM

    Ondina D.F.'s Avatar

    I found the culprit. In your InterfaceView.init() you add 2 more views to the stage. The problem is, that by that time, InterfaceView isn't added to stage yet. When the 2 views are added after InterfaceView is on stage, everything works fine.
    I tried it in a Flex app as well. It works without any issues. It is a pure as3 problem, due to the way mediators are created.

    I've attached 2 files. Yours modified and another one, which is a Flex app.
    The modification to your code:

    I created the context in the added to stage handler of the main view.
    I added InterfaceView in the afterInitilizing handler of the context, so that you don't need to do it in a command.
    I added MainMenuView and SideMenuView on the added to stage of InterfaceView.

    I created 2 more packages: baseViews and otherViews, where I use an interface - IBaseView that is injected into JustABaseMediator.

    The mappings:

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

    Just take a look at the classes to see what I mean. Too much to describe in detail and too little time right now;)

    hth

    P.S. Your app is now an AIR one, because it was easier for me to work with in FlashBuilder

  8. 8 Posted by Jono on 25 Oct, 2014 12:53 AM

    Jono's Avatar

    Thanks very much for this. I'll look into the examples and let you know if I have any more questions. On initial look, is it regarded good practise to use context.afterInitializing to start a project?

  9. Support Staff 9 Posted by Ondina D.F. on 27 Oct, 2014 11:15 AM

    Ondina D.F.'s Avatar

    You're welcome, Jono.

    On initial look, is it regarded good practise to use context.afterInitializing to start a project?

    afterInitializing is exactly what the name suggests: a new context has been created, the context has installed all extensions, and the mappings/wirings/configurations are done for all your classes, so that they are ready to work and interact with each other. It's not about good or bad practice. It just depends on your use case, whether you need to do anything after the context has been initialized or not. For example, afterInitializing would be a convenient place to :

    • add Views to a contextView (for navigational purposes)

    • make a service call to which a certain mediator should react (avoiding race conditions)

    • have access to the shared event dispatcher

    • many other scenarios, but I can't think of any others right now

    Your SetupCommand suggested to me that you needed to add a view after context initialization, that's why I showed you how to use context.afterInitializing.

    In my projects I use option a or c from my response in this discussion:

    http://knowledge.robotlegs.org/discussions/robotlegs-2/4493-dispatc...

  10. Ondina D.F. closed this discussion on 05 Dec, 2014 11:52 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