Mediator mapping and override error

dada's Avatar

dada

05 Nov, 2013 04:21 AM

Hi all,

I read another thread about my problem (that is closed : http://knowledge.robotlegs.org/discussions/robotlegs-2/698-mapping-...) but it doesn't help me.

WIth RobotLegs 1, I always used injection to instanciate my views, in addition of using view/mediator mapping.
Today, if I do this :

 _injector.map(TimelineView).asSingleton();
 _mediatorMap.map( TimelineView ).toMediator( TimelineMediator );
I got an error cause of mapping override.
But if I remove the mapping as singleton, I can't inject my view into another view, and can't use injector to instanciate it.

So, the question : how to use injection to instanciate a view, while using view/mediator association ?

Thanks.

  1. Support Staff 1 Posted by Ondina D.F. on 05 Nov, 2013 09:32 AM

    Ondina D.F.'s Avatar

    Hey dada,

    Instead of the mediatorMap, use the viewProcessorMap, like this:

    injector.map(SomeView).asSingleton();
    
    viewProcessorMap.map(SomeView).toProcess(new MediatorCreator(SomeMediator));
    
    mediatorMap.map(AnotherView).toMediator(AnotherMediator);
    mediatorMap.map(ShellContextView).toMediator(ShellContextMediator);
    

    or instead of mapping the view as singleton, you can map it like so:

    var someView:SomeView = new SomeView();
    injector.map(SomeView).toValue(someView);
    

    You could as well inject SomeView directly into views:

    Inside of AnotheView and ShellContextView: 
    [Inject]
    public var someView:SomeView;
    

    Mappings:

    var someView:SomeView = new SomeView();
    injector.map(SomeView).toValue(someView);
    
    viewProcessorMap.map(AnotherView).toInjection();
    viewProcessorMap.map(ShellContextView).toInjection();
    

    Now, you have to know that when you add SomeView to ShellContextView, and then you want to add it to AnotherView as well, SomeView will be re-parented, i.e. first removed from ShellContextView and then added to AnotherView, and vice versa when you add it again to ShellContextView, so SomeMediator will be destroyed and created again.

    Does that answer your question?

    Ondina

  2. 2 Posted by dada on 05 Nov, 2013 11:53 AM

    dada's Avatar

    Yes, that works fine with the MediatorCreator, thank you for your help.

    Have a nice day|night.

  3. Support Staff 3 Posted by Ondina D.F. on 05 Nov, 2013 12:05 PM

    Ondina D.F.'s Avatar

    Glad it works.

    Thanks for the wishes, have a nice day/night, too :)

    I forgot to give you this link for more info on viewProcessorMap's usage:

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

  4. Ondina D.F. closed this discussion on 05 Nov, 2013 12:05 PM.

  5. dada re-opened this discussion on 05 Nov, 2013 12:06 PM

  6. 4 Posted by dada on 05 Nov, 2013 12:06 PM

    dada's Avatar

    Thanks for the link, I'll have a look at it.

  7. Ondina D.F. closed this discussion on 15 Nov, 2013 11:46 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