Making an interface to deal with injects

zmaldonado's Avatar

zmaldonado

17 Jul, 2014 05:03 PM

So, now that I have signals working all fine and dandy, I find myself with some mediator classes that have quite a few injections and I'm wondering what the best way of just cleaning up code is when it comes to injections. All code structure aside (whether the number of injections I have really is necessary) is it possible to create some sort of interface for a mediator class that does all of the injection work?

As I am writing this, I realize I could just make another class, inject all the values in there, and have my mediator inherit that class, but I'm still curious if there is an approach that uses interfaces. Thank you!

-Zack

  1. 1 Posted by zmaldonado on 17 Jul, 2014 05:06 PM

    zmaldonado's Avatar

    Then again, after trying to implement a class inheriting injections from another class, I realize that I have no idea what the config would look like.

    EDIT: The answer? It doesn't change the config at all! So, yes, this method does actually work.

  2. Support Staff 2 Posted by Ondina D.F. on 18 Jul, 2014 08:43 AM

    Ondina D.F.'s Avatar

    I'm wondering what the best way of just cleaning up code is when it comes to injections.

    As you well know by now, mediators are created when their views are added to the stage and destroyed when the views leave the stage, provided the autoRemove was set to true (which is the default) when you mapped a view to a mediator.
    The destroy method of a mediator is a convenient place to do some clean up work.
    Event listeners added through addContextListener or addViewListener are automatically removed when the mediator is destroyed.

    That's not the case for signals or for events listeners added directly to views and/or their subcomponents.
    They keep mediators alive, thus causing garbage collection issues. You need to override the destroy method and remove such listeners manually, if you wish to spare yourself a lot of unnecessary debugging and headaches;)

    override public function destroy():void
    {
        someSignal.remove(someListener);
        super.destroy();
    }
    
  3. 3 Posted by zmaldonado on 18 Jul, 2014 08:50 PM

    zmaldonado's Avatar

    Oh wow, thanks! I didn't even think that signals wouldn't get garbage collected. Thanks, Ondina!

  4. Support Staff 4 Posted by Ondina D.F. on 21 Jul, 2014 02:01 PM

    Ondina D.F.'s Avatar

    You're welcome!

  5. Ondina D.F. closed this discussion on 21 Jul, 2014 02:01 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