RL2 Migration extension

Paul Robertson's Avatar

Paul Robertson

04 Apr, 2012 10:18 PM

I'm trying to figure out how to use the RL2 migration extension (github.com/robotlegs/robotlegs-extensions-migration).

For reference I'm looking at Till's Cafe Townsend migration example as well as dartavion's "Robotlegs2Example" with Shaun's updates.

I'm actually trying this out in a very simple project, my "simple" example: https://github.com/probertson/robotlegs-examples-Simple
It's a simple app that demonstrates a single view->service->model->view round trip.

  • There is a button that triggers an event that calls a service to open a File chooser dialog. (It's an AIR app.)
  • When the file is selected, the service dispatches an event that calls a command that sets the file path in a var in a model.
  • Then the model dispatches an event that a mediator catches, updating a text field with the file path.

I dropped in the RL2 SWC and the migration SWC and deleted the RL1 SWC. Everything compiles -- so far so good. Next I updated the declaration in the main MXML file like so:

<fx:Declarations>
    <rl2:ContextBuilderTag>
        <mvcs:MVCSBundle/>
        <migration:MigrationExtension/>
        <simple:SimpleConfig/>
    </rl2:ContextBuilderTag>
</fx:Declarations>

Then I copied my context into a new SimpleConfig class, making it a plain class with a [PostConstruct] tag on the startup() method:

public class SimpleConfig
{
    [Inject]
    public var injector:IInjector;

    [Inject]
    public var mediatorMap:IMediatorMap;

    [Inject]
    public var commandMap:ICommandMap;

    [PostConstruct]
    public function startup():void
    {
        commandMap.mapEvent(SimpleAppEvent.CHOOSE_FILE, ChooseFileCommand, SimpleAppEvent);
        commandMap.mapEvent(FileResultEvent.FILE_RESULT, SetSelectedFileCommand, FileResultEvent);

        injector.mapSingletonOf(IFileService, FileService);

        injector.mapSingleton(SimpleModel);

        mediatorMap.mapView(ButtonContainer, ButtonContainerMediator);
        mediatorMap.mapView(TextContainer, TextContainerMediator);
    }
}

When I run the app and click the button, nothing happens -- as though something isn't being wired up. I stuck in some breakpoints and found that the startup() method is called but that the onRegister() method in my mediator isn't being called.

I already went through the normal RL1 "why isn't onRegister() being called" checks -- making sure I really mapped the mediator, making sure the view's addedToStage event is being triggered after the Config.startup() method, etc.

Do you have any advice on how to make this work? Are there other migration steps that I'm missing? (Obviously with such a simple app I could go all the way to migrating it to RL2, but that's not the point -- I'm trying to learn/figure out the migration process so I can apply it to more complex apps so I want to do it step-by-step.)

If you want to see the full code, I've pushed my changes to the repo in a new branch and made that branch the default:
https://github.com/probertson/robotlegs-examples-Simple

Thanks,
Paul

  1. Support Staff 1 Posted by Ondina D.F. on 05 Apr, 2012 11:49 AM

    Ondina D.F.'s Avatar

    Hi Paul,

    I managed to make the Mediators work by using
    [PostConstruct] override public function onRegister():void

    and the rl2 mediatorMap for the mappings, since the idea is to migrate from rl1 to rl2.
    Hopefully I’m not mistaken about the usage of this MigrationExtension.

    In SimpleConfig

    
    import robotlegs.bender.extensions.mediatorMap.api.IMediatorMap;
    [PostConstruct]
    public function startup():void
    {
    …
    mediatorMap=injector.getInstance(IMediatorMap);
                
    //mediatorMap.mapView(ButtonContainer, ButtonContainerMediator);
    //mediatorMap.mapView(TextContainer, TextContainerMediator);
    
    mediatorMap.mapView(TextContainer).toMediator(TextContainerMediator);
    mediatorMap.mapView(ButtonContainer).toMediator(ButtonContainerMediator);
    …
    

    TextContainerMediator

    
    import org.robotlegs.mvcs.Mediator;
    
    [PostConstruct]
    override public function onRegister():void
    {
    trace("TextContainerMediator.onRegister()");        
    addContextListener(SimpleModelEvent.FILE_NAME_CHANGE, onFileNameChange, SimpleModelEvent);
    addContextListener(SimpleModelEvent.FILE_PATH_CHANGE, onFilePathChange, SimpleModelEvent);
    }
    

    Ondina

  2. Support Staff 2 Posted by Till Schneidere... on 05 Apr, 2012 11:52 AM

    Till Schneidereit's Avatar

    Hey Paul,

    the migration extension is currently very much work in progress. In
    fact, I extended its functionality exactly as far as I needed for the
    Cafe Townsend example to work before my FITC Amsterdam talk a few
    weeks ago.

    That being said, the MediatorMap is also pretty rough still, so that
    might also be the reason. I think I might remember `onRegister()` not
    being wired up at all, so you could try adding `[PostConstruct]`
    metadata to that and see if it gets fired then.

    cheers,
    till

  3. Support Staff 3 Posted by Shaun Smith on 05 Apr, 2012 12:13 PM

    Shaun Smith's Avatar

    Hi Paul,

    Thanks for the sample app - it helped me track down the issue. You'll need to grab the latest framework and extension code, and that should sort you out (no changes to the sample app required).

  4. 4 Posted by Paul Robertson on 05 Apr, 2012 06:54 PM

    Paul Robertson's Avatar

    Thanks to all of you for the quick responses. I'll pull down the latest
    version of the extension and give it a try this evening.

    Paul

  5. Ondina D.F. closed this discussion on 27 Aug, 2012 10:37 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