Multiple views controlled by one Mediator

grapefrukt's Avatar

grapefrukt

05 Nov, 2009 01:53 PM

Before I had a view class, ImageStrip and a corresponding ImageStripMediator that worked just fine.
Now I need some slightly different behaviors in two places, so I made to subclasses of ImageStrip: KeyedImageStrip and BackgroundImageStrip and corresponding mediators for them.

I tried letting the two new mediators subclass ImageStripMediator since this has code I want to use. But since this is set up to be injected with a ImageStrip things start to get hairy:

 Error: Injector is missing a rule to handle injection into target [object KeyedImageStripMediator]. Target dependency: se.psweb.kromaki.view.menu::ImageStrip

So, how do I use subclasses of a view (with mediator) and have mediators for those too?
And if this is completely backwards, how should I do it?

  1. 2 Posted by System on 05 Nov, 2009 02:29 PM

    System's Avatar

    An internal ticket was created for this discussion

  2. Support Staff 3 Posted by Joel Hooks on 05 Nov, 2009 02:41 PM

    Joel Hooks's Avatar

    Perhaps using setter injection might be a better route. Then you could override the setter and [Inject(name="whatever")] on the method setting the protected value.

  3. Support Staff 4 Posted by Shaun Smith on 05 Nov, 2009 02:57 PM

    Shaun Smith's Avatar

    If your KeyedImageStripMediator depends on ImageStrip, you can pass it into injectViewAs when calling mapView(), like so:

    mapView(KeyedImageStrip, ImageStripMediator, ImageStrip);

    This will create an ImageStripMediator when a KeyedImageStrip lands on stage, but it will inject the KeyedImageStrip as an ImageStrip (which is what your Mediator actually depends on).

    Does that help at all?

  4. 5 Posted by grapefrukt on 05 Nov, 2009 03:29 PM

    grapefrukt's Avatar

    I temporarily sidestepped the issue by duplicating the code from ImageStripMediator in the two new mediators. It was just a line or two, still, not very pretty. Sadly, with the way my current deadline is looming it'll have to stay that way until I've got some more tinkering time.

    But I think this could be solved with either method, Joels is more tailored to my specific need but i think Shauns is a bit less magical ;)

  5. Support Staff 6 Posted by Shaun Smith on 07 Dec, 2009 02:28 PM

    Shaun Smith's Avatar

    Hi Grapefrukt,

    I believe that:

    mapView(KeyedImageStrip, ImageStripMediator, ImageStrip);

    would be the best solution to this problem. I'm going to close this issue for now, but please feel free to re-open it if you feel the answer to be dis-satisfactory.

  6. Shaun Smith closed this discussion on 07 Dec, 2009 02:28 PM.

  7. Support Staff 7 Posted by Shaun Smith on 11 Dec, 2009 08:55 PM

    Shaun Smith's Avatar

    Actually, I think I misunderstood the core issue here. See response to:

    http://knowledge.robotlegs.org/discussions/questions/21-subclassing...

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