ViewMap and injecting into views

Safa Sofuoğlu's Avatar

Safa Sofuoğlu

15 Feb, 2012 09:38 AM

Hello,

We are developing a game, where we have a dynamic bitmap asset repository and a configuration provider model which holds some values required by all parts of the application.
We need to access the asset repository and configuration provider from views, so our current options are:

  1. Inject those two models into our views using ViewMap
  2. Inject those two models into our views in onRegister() of the view's mediator
  3. Inject those two models into our view's mediator and pass them to the view as parameters

I see that you strongly discourage using MediatorMap and ViewMap together. What do you suggest in this scenario?

Thanks,

  1. 1 Posted by bulupe on 15 Feb, 2012 04:17 PM

    bulupe's Avatar

    Hi Safa,

    The suggested way to to this by stray and others - also we are doing - is creating a command which will access your models and dispatch an event with the data needed.
    Then you can on your mediator dispatch and event which will be picked up by the command. Also your mediator should listen to the event which will command dispatches.

    You can then update your view with data from event. Injecting models in to mediators or views are highly discouraged.

    Check strays second comment on here: http://knowledge.robotlegs.org/discussions/questions/309-inject-mod....

    Bülent Öztürk
    Take care.

  2. 2 Posted by Safa Sofuoğlu on 15 Feb, 2012 08:44 PM

    Safa Sofuoğlu's Avatar

    Thank you Bülent, we are also following that approach.

    I thought that in some exceptional cases, injecting into views may be the only feasible solution, such as:

    http://knowledge.robotlegs.org/discussions/problems/149-injection-i...

    What we have here is also an exceptional case. We have views that need about a hundred assets. We also need a way to fill the constant values and l10n-compatible strings in views.

    Request-fulfill approach looks too heavy for these jobs, both in terms of performance and amount of code needed.

    So we are looking for other possible solutions.

  3. 3 Posted by bulupe on 15 Feb, 2012 09:07 PM

    bulupe's Avatar

    Hi again,

    I think such a special case may need a specific behavior, what about holding assets in a skin class with public static access, have you ever examine stray's strategy game?

    https://github.com/Stray/robotlegs-demo-StrategyGame

    Bulent

  4. Ondina D.F. closed this discussion on 29 Feb, 2012 11:23 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