Is there any way to easy destroy config?

ishaban.flash's Avatar


05 Mar, 2014 03:26 PM

I have requirement to dynamic configure application, so i want to add \ remove different configs. I can easy add new configs, but i don't see any way to clear old ones. I wish to make mapping manually, but all unmapping process i wanna automate if it possible. So mb anyone can provide similar solution. (e.g. like mediators has methods "addContextListener" \ "addViewListener", wich remove whole mapped listeners on destroy)

As i understand i should use child injector, and call Inject#teardown method to "destroy" it, but how i can unmap mediators and commands?

  1. Support Staff 1 Posted by Ondina D.F. on 06 Mar, 2014 10:36 AM

    Ondina D.F.'s Avatar


    As i understand i should use child injector, and call Inject#teardown method to "destroy" it, but how i can unmap mediators and commands

    Why would you want to use teardown() ?

    Injector's teardown() destroys the injector by cleaning up all instances it manages.

    When a context is destroyed, teardown() is called automatically.

    As you know, when a contextView is removed from stage, the context gets destroyed automatically, thus you don't need to manually unmap your classes. Everything that was mapped inside of this context will get unmapped before the injector and the context are destroyed.

    If you don't want to remove the context view from stage, but you want to destroy the context manually, you use context.destroy().

    Now, I'm not sure I understand what you mean by dynamic configuration.

    A. Do you need to use different configs when you create a new context,

    B. or do you want to change the config inside the same context at run time?

    A. That's pretty easy. There, where you create the context, you give it different configs depending on some conditions. When the context is destroyed, the mappings in those configs are gone.

    B. You could create a class that contains the desired unmappings. You could access it inside a command, for example. The command could also access the new configs containing the new mappings.
    But, beware of what could happen to your mediators, if you remove the mappings for your views while they are still on the stage. If you need to unmediate them after unmaping them, you'll have to also mediate them manually after adding the new configs.

    So, the Injector can either remove all mappings of a certain context when the context is destroyed (A), or only the ones you specify directly through commandMap.unmap, mediatorMap.unmap or injector.unmap (B).

    In case I missed your point, could you explain what exactly you want to achieve by "dynamic configuration"?


  2. 2 Posted by ishaban.flash on 06 Mar, 2014 01:58 PM

    ishaban.flash's Avatar

    Hi, there is case "B", but i want to unmap all automatic, just to call any method, like "destroy", and do not write commandMap.unmap, mediatorMap.unmap.

  3. Support Staff 3 Posted by Ondina D.F. on 07 Mar, 2014 10:29 AM

    Ondina D.F.'s Avatar

    but i want to unmap all automatic, just to call any method, like "destroy", and do not write commandMap.unmap, mediatorMap.unmap.

    In my mind, that would require implementing a special mapping mechanism, where you could build a "group" of mappings, so that you could refer to that group when you want to unmap all the classes inside of it.
    Since the mappings are performed by different "mappers" (commandMap, mediatorMap, Injector itself), each of them should have an additional method for storing the mappings in a dictionary of groups."someGroup");"someGroup");"anotherGroup");, SomeEvent).toCommand(SomeCommand).toGroup("someGroup");

    toGroup is of course a silly name:)

    Then when you want to unmap them, calling


    would result in each "mapper" iterating through its own mappings-dictionary in order to unmap the classes belonging to "someGroup".

  4. 4 Posted by ishaban.flash on 07 Mar, 2014 12:15 PM

    ishaban.flash's Avatar

    Is it possible to implement this like separate extension, or add new features directly in framework?

  5. Support Staff 5 Posted by Ondina D.F. on 07 Mar, 2014 03:43 PM

    Ondina D.F.'s Avatar

    You could try opening a feature request ticket on github:

  6. Support Staff 6 Posted by creynders on 12 Mar, 2014 03:32 PM

    creynders's Avatar

    Hey Ishaban,

    I saw your issue on GH. It sounds to me like you're trying to replicate module-like behaviour, but without using modules? However, I'd definitely recommend using modules with separate contexts for something like this. Here's a demo for how to create an application with modules in RL2:

  7. 7 Posted by ishaban.flash on 12 Mar, 2014 04:02 PM

    ishaban.flash's Avatar

    Hm, not exactly, i want to got one context and just extent functionality for a some time, and after remove it as easy as it possible. I don't want to create many contexts.

  8. Support Staff 8 Posted by creynders on 13 Mar, 2014 05:27 PM

    creynders's Avatar

    Well yes, but that's what contexts are for. They manage groups of mappings.
    With IContext#addChild and IContext#removeChild you can create a hierarchy
    of contexts.

  9. 9 Posted by ishaban.flash on 14 Mar, 2014 08:51 AM

    ishaban.flash's Avatar

    As for me, use context is too excess solution, because when i create new context i should initialize it with all extensions, also adds several problems with comunitation between contexts. I don't need to load any logic at runtime, all logic already included in application i just need change it. But all i need is to add few mappings, e.g.:

    public class ConcreteProfile extends BaseProfile {
        override protected function mapInjections() : void {
  , PopupFactory.PAYTABLE).toType(BasePaytableView).toGroup(groupName);
  , PopupFactory.FREE_SPINS_RETRIGGERED).toType(RetriggerFreeSpinsWindow).toGroup(groupName);
  , PopupFactory.FREE_SPINS_END).toType(EndFreeSpinsWindow).toGroup(groupName);

    and then:


    I know that i can initialize child context with parent's contextView, but afaik all extensions i should initialize every time, and that scary me, because i care about perfomance.. If i don't right please correct me.

  10. Support Staff 10 Posted by creynders on 14 Mar, 2014 12:38 PM

    creynders's Avatar

    AFAIK you don’t need to install the bundles again when you create a child context. Just add a config to it.
    (Sorry, don’t have the time to test it out)

    Something like this:

    var childContext = new Context().configure(GroupConfig);
  11. 11 Posted by ishaban.flash on 14 Mar, 2014 12:59 PM

    ishaban.flash's Avatar

    Looks niiiice, thanks you, i will work around it. :)

  12. 12 Posted by matej on 14 Mar, 2014 03:52 PM

    matej's Avatar

    I think this works also, not sure :)

  13. 13 Posted by ishaban.flash on 17 Mar, 2014 01:49 PM

    ishaban.flash's Avatar

    So, i make test and those code doesn't work for me(( But next code valid:

    public class Test extends Sprite {
        private var _context : IContext;
        public function Test() {
            _context = new Context()
                    .configure(new ContextView(this));
            var childView : Sprite = new Sprite();
            var childContext : IContext = new Context()
                    .configure(new ContextView(childView));

    That means that i should initialize all extensions for child context, what i doesn't need. Also, as i see, every context creates own injector, but mediatorMap \ commandMap, creates in extensions.
    Maybe i miss something or you have another advice?

  14. 14 Posted by matej on 17 Mar, 2014 02:16 PM

    matej's Avatar

    You can initialise just the extensions you need.
    Mediator Map, Signal command map ext .. that you use.

    No need to use new context view, just pass the child config and then call context.initialize();

    and when you want to finish it, you call context.destroy();
    You can add context view also, but check inside MVCS bundle, not all of that you need.

    this is what you wanted, I suppose.

  15. 15 Posted by ishaban.flash on 17 Mar, 2014 02:33 PM

    ishaban.flash's Avatar

    Can you provide small example? I install context with custom MVCSBundle, in child context i want install only command \ mediator maps, but all my tries has no luck(( Context doesn't initialize.

  16. Support Staff 16 Posted by Ondina D.F. on 18 Mar, 2014 10:32 AM

    Ondina D.F.'s Avatar


    I know that the following example is not exactly what you want, but at least it shows how you can use a custom bundle with just a few extensions. Since the extensions needed for listening for the added to stage event for views are missing, you need to mediate the view manually and also to initialize the childContext manually (see below), as Matej has already mentioned.

    If you need a mediator map and a command map, these are the required extensions for a child context to work:

    public class ChildMVCSBundle implements IBundle
        public function extend(context:IContext):void
            //context.logLevel = LogLevel.DEBUG;            

    In the parent Context, or there where you add a child context:

    protected function onAddChildContext(event:Event=null):void
        childContextView = new ChildOneView();
        childContext = new Context();
        childContext.configure(new ContextView(childContextView));  
        (contextView.view as Object).addElement(childContextView);      
    private function childAfterInitializing():void
        var childMediatorMap:IMediatorMap = childContext.injector.getInstance(IMediatorMap);

    Hope that helps a little:)


  17. Ondina D.F. closed this discussion on 28 Apr, 2014 08:12 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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