2

I'm using robot legs framework and wondering how mediator.mapView works with multiple instances of the same view. For example, in the following, is a new ItemDisplayMediator created for every ItemDisplay instantiated, or do all ItemDisplay's use the same mediator? If they each instantiate a new mediator, is it possible to use a single mediator for multiples of the same class/view?

mediatorMap.mapView(ItemDisplay, ItemDisplayMediator);
Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
typeoneerror
  • 55,990
  • 32
  • 132
  • 223

2 Answers2

2

Each view instance is mediated by a different Mediator instance.

If you want a single mediator for multiple items, then create a Mediator for a container and mediate its children.

alecmce
  • 1,456
  • 10
  • 23
  • Makes sense. Someone mentioned to me "using interfaces for preventing the duplications of views" (I'm guessing he meant using something similar to RL's mapSingletonOf for a view though) ...not sure if that's a reality. – typeoneerror Feb 20 '10 at 23:55
  • 1
    Yeah, I'm really not sure what he was talking about! I just tried mapping your mediator as a singleton as well as to a view... but RobotLegs ignored the singleton mapping. – alecmce Feb 21 '10 at 05:42
1

alecmce is correct, the MediatorMap is going to apply a new instance of the mediator to each instance of the view that is being mediated comes onto the stage. A mediator, as it is written in robotlegs, is only equipped to handle a single view component at any given time. The actual mediator isn't injected anywhere, so it isn't mapped with the injector.

Joel Hooks
  • 6,465
  • 4
  • 33
  • 39