Making a DisplayObject eligible for injection

Ciprian Caba's Avatar

Ciprian Caba

10 Jun, 2011 12:08 AM

Hi,

Is it possible to make a view instance (any DisplayObject from the stage) eligible for injection in the robotlegs framework?
I can have like 3 view components on the main app that are too basic to require mediation. Can I mediate them from an existing Mediator or Command?

Thanks,
Ciprian

  1. 1 Posted by Michal Wroblews... on 10 Jun, 2011 08:31 AM

    Michal Wroblewski's Avatar

    It's not the best practice but that is the best part about Robotlegs you can work the way you like using only parts of the framework that you really need.

    About your problem. Create view instances and use injector to map that value:
    injector.mapValue(YourViewClass, yourViewInstance) If you want to use it in a Mediator make sure you do the mapping of view instances before Mediator is created, or use injector.getInstance(YourViewClass) when you are sure you did the mapping

    Cheers,
    Michal

  2. Support Staff 2 Posted by Stray on 10 Jun, 2011 10:08 AM

    Stray's Avatar

    Michal is spot on - the difference though is that the mediatorMap cleans up the injections straight away when views are set on mediators. So, you'll have those injections permanently in the injector unless you unmap them - and that will prevent garbage collection.

    But... first I just want to check something out - you said:

    "I can have like 3 view components on the main app that are too basic to require mediation. Can I mediate them from an existing Mediator or Command?"

    They're too basic to require mediation, and yet you want to mediate them? Hmm...

    It's ok to have very light mediators with very little functionality - that small-simple-classes workflow has many benefits. If you need to share behaviour between mediators then break it out into helper classes - just as you would with any normal OO code.

    So - Michal has given you a good working solution, but I think you should also consider these alternatives:

    1. Mediate them directly, or
    2. Mediate them through their parent view

    Mediator granularity is really flexible in Robotlegs, but generally it's best to go for the simplest solution available. A simple solution that breaks DRY beats a complex one that has unintended consequences in my book (and then you can always DRY it up later).

    Stray

  3. 3 Posted by Ciprian Caba on 10 Jun, 2011 10:14 AM

    Ciprian Caba's Avatar

    Hi,

    I usually use one mediator for one view. But i stumbled upon the issue of not being able to easily inject into the application a view that has no mediator attached. I wanted to know if this can be done or if it's a technical restriction.

    Thank you for the answers
    Ciprian

  4. Support Staff 4 Posted by Stray on 10 Jun, 2011 01:20 PM

    Stray's Avatar

    Hi Ciprian - robotlegs can do almost anything - it turns into a robot helicopter if you know the secret key combination ;)

    So - do you want to describe your use case and we'll give you a direction on the best route to take to achieve it?

    Stray

  5. Support Staff 5 Posted by Ondina D.F. on 02 Nov, 2011 03:36 PM

    Ondina D.F.'s Avatar

    Hi Ciprian,
    If you want to continue this discussion, feel free to reopen it. I’m closing the thread now.
    Please open new threads for new issues.
    Thank you.
    Ondina

  6. Ondina D.F. closed this discussion on 02 Nov, 2011 03:36 PM.

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