Mediator maps value twice

AntonY's Avatar


03 Apr, 2013 05:40 PM


I've been looking for the solution, but didn't find it. So, I hope it's OK, that I've created this discussion.

I've faced one problem. I'm using [robotlegs]+[starling]+[feathers]+[robotlegs-starling-plugin] in my project.
I've got the RootView and RootViewMediator. In RootView i have a navigator to switch between SubViews.
Say, I've got ViewA and ViewAMediator and ViewB with ViewBMediator.
A can switch between ViewA and ViewB using navigator in RootView.
Imagine I'm on ViewA. When i switch to ViewB and then back to ViewA fast enough, i see, that onRegister() in ViewAMediator is called for the second time before onRemove(). So, i see the next error message in the console:

Warning: Injector already has a rule for type "ViewAMediator", named "".
If you have overwritten this mapping intentionally you can use "injector.unmap()" prior to your replacement mapping in order to avoid seeing this message.

What am I doing wrong?

Thanks a lot,

  1. 1 Posted by anton.yakovenko... on 03 Apr, 2013 06:34 PM

    anton.yakovenko1991's Avatar

    Hm...I've found the following line of code in

    setTimeout(removeMediatorLater, 500, null);

    Because of this delay in 500 ms, onRegister() is called for the second time before onRemoved() was called for the first time.

    Did anyone face this problem?

  2. Support Staff 2 Posted by Ondina D.F. on 04 Apr, 2013 10:41 AM

    Ondina D.F.'s Avatar

    Hi Anton,

    Good catch.
    You could open an issue here:,
    but who knows whether the starling plugin for robotlegs 1 will be updated….

    The extension for robotlegs 2 works fine.

    forked from:

    with example:

    Note: I don’t know if the above mentioned rl2 extensions work with the latest build of rl2.

    Many things are better, and easier to do in rl2. I recommend using it :)


  3. 3 Posted by anton.yakovenko... on 09 Apr, 2013 08:17 AM

    anton.yakovenko1991's Avatar

    Thanks a lot!

    I think I'll check RL2.
    Could you tell me, are there major differences between RL1 and RL2?


  4. Support Staff 4 Posted by Ondina D.F. on 09 Apr, 2013 04:23 PM

    Ondina D.F.'s Avatar

    Hey Anton,

    Could you tell me, are there major differences between RL1 and RL2?

    There are differences between the 2 versions. I won’t be able to mention all of them in much detail, because I would end up writing a tutorial, and I’m afraid I wouldn’t be very good at it and it would take me too long.
    I’ll try to do my best though. I’ll explain just a few terms to get you started.
    Some of the definitions used bellow are extracted from the docs on github, some others are my own interpretations..
    The main key words: extension, bundle, configuration, installation, contextView, context

    Let’s start here:
    Read the READMEs, too!

    You can see the new strucutre:

    -extensions []

    -bundles []

    -framework []

    An extension integrates a single utility or library into a Robotlegs context.

    A bundle bundles up a selection of extensions and configurations into a single drop-in package.

    A configuration is a custom class, where you map your mediators, commands, or whatever you need to make your app work as expected.

    The Context View represents the root DisplayObjectContainer for a Context

    A context is a scope. It is core to any application or module built using Robotlegs.

    The Context adds framework features by composition – installs extensions.
    For example, if an rl2 app uses Mediators, the needed extension is… you guessed it… MediatorMapExtension. If you’ll never use Commands, then the CommandCenterExtension doesn’t need to be installed into your Context.
    Very flexible, isn’t it?

    There are a few built-in extensions. For an MVCS app you’d need the extensions provided by the MVCSBundle.[]

    For special needs, developers can build their own extensions or use the ones built by others (for example - An extension to enable integration of Starling, Away3D 4.0, Robotlegs and Signals.)

    Now, you might ask: should I care about those extensions and bundles and all framework classes?
    Yes and no.

    Knowing which extension does what might help you decide what to use for a certain use case.
    Say, you wanted to have Modules in your app. The ModularityExtension is already included in the MVCSBundle, but if you wanted your modules to communicate with each other, you’d need the ScopedEventDispatcherExtension, too.

    What’s different from rl1? All of the above and...

    • You don’t need to extend the Context class anymore. To create a context simply instantiate a new Context and provide some configuration:
    _contextView = new ContextView(this); ;// DisplayObjectContainer
    _context = new Context()
    .configure(MediatorsConfig, ModelsConfig, contextView);
    class MediatorsConfig implements IConfig
            public var mediatorMap:IMediatorMap;
            public function configure():void
    • You don’t need to split up your bootstrapping process into several commands anymore. You can organize your mappings by using custom config files, say MediatorsConfig, CommandsConfig, ModelsConfig, etc

    • an rl2 Mediator overrides initialize() instead of rl1’s onRegister, and destroy() instead of onRemove

    • Commands don’t need to override execute() anymore and also don’t need to extend Command. Any class with a public execute method can be used.

    • there is no Actor in rl2 anymore. You can use any class for your Models and Services and if you want them to be able to dispatch events on the shared event dispatcher, you inject the dispatcher like this:

    public var dispatcher:IEventDispatcher;
    • swiftsuspenders v.2 ’s new syntax. Here, just a few common mappings:
    rl1: mediatorMap.mapView(SomeView, SomeMediator);
    rl1: commandMap.mapEvent(SomeEvent.SOME_TYPE, SomeCommand, SomeEvent, true);
    rl2: SOME_TYPE).toCommand(SomeCommand);
    rl1: injector.mapSingleton(SomeModel);

    Easy, right?

    For starters, keep in mind that the minimum you’d need to build an rl2 app is a ContextView, a Context, the MVCSBundle and your own configuration file(s).

    Other -very cool- new features (you don’t need to care about them right now though): guards, hooks, lifecycle, ViewProcessorMapExtension

    I suggest looking at examples [], even if not all of them have been updated to work with the latest rl2 build. Also, go through the entire documentation on github, just to get familiar with the new terminology and classes. Try out a simple example and come back to our forum to ask specific questions, if you get stuck. We’ll do our best to help you become a happy rl2 user ;)

    I hope my incomplete mini-guide will help you, at least a little bit, to get started.


  5. 5 Posted by anton.yakovenko... on 10 Apr, 2013 02:26 PM

    anton.yakovenko1991's Avatar

    Thanks, I could not get better answer!)

    By the way, I have found this fork of robotlegs starling pluin:

    Looks like it works well without warnings.

    Robotlegs Support Rocks! :)

  6. Support Staff 6 Posted by Ondina D.F. on 12 Apr, 2013 08:59 AM

    Ondina D.F.'s Avatar

    You're welcome and thanks for the kind words!
    Closing this thread for now.

  7. Ondina D.F. closed this discussion on 12 Apr, 2013 08:59 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