Mediator's onRegister() is called after a Model's [PostConstruct] function, which is dispatching an event

kerry.kim.russo's Avatar

kerry.kim.russo

29 Jun, 2012 07:09 PM

This may be a simple problem.

I have a model called PhrasesModel which has a function, randomize(), that get's tagged with [PostConstruct]. The randomize function sets a setter function, which dispatches a CHANGE event. My Mediator, TestRobotlegsTextFieldMediator, has a context listener being set up in onRegister(). The problem is that the dispatch is occurring before onRegister() so the event doesn't get captured. There's a button that can be clicked and essentially calls all of these functions. The reason I'm calling randomize() using [PostConstruct] is that 1) I was getting an error when i tried to do it in the constructor because the eventDispatcher wasn't ready yet and 2) I would like the textfield to be populated with data initially.

How do I wait for the my Mediators onRegister() functions to complete? Would I dispatch an event from the Mediator which calls a command? Or is there a more elegant solution?

  1. Support Staff 2 Posted by Ondina D.F. on 02 Jul, 2012 02:07 PM

    Ondina D.F.'s Avatar

    Hi Kerry,
    Sorry for the late answer.
    You posted your question under the Robotlegs 2 category, but you mentioned onRegister(), which is a Robotlegs 1 method. Now, if you’re using rl2, I’d rather let Shaun or Stray answer your question, because I’m not sure if there are new features that would make it easier for you to solve your problem in a “more elegant way” :)

    In Robotlegs 1 there are just a couple of solutions, I know of:

    • Stray’s RelaxedEventMap (https://github.com/Stray/robotlegs-utilities-RelaxedEventMap) – probably the best solution

    • ask for data within your onRegister() method: dispatch an event triggering a command, that calls the Model (after registering an event listener for the event dispatched by the Model in Mediator’s onRegister())

    • the disputed ‘Inject your Model into your Mediator’ – with probably more nays than ayes . I’m abstaining ;)

    • depending on your application’s design, there might be other solutions as well, but from what you wrote is hard to tell which ones would be best for you

    Cheers
    Ondina

  2. 3 Posted by kerry.kim.russo on 02 Jul, 2012 02:17 PM

    kerry.kim.russo's Avatar

    Not a problem. Appreciate the feedback!

    Sorry for any confusion. I was following a Robotlegs tutorial (http://www.developria.com/2010/06/an-introduction-to-robotlegs-a-1....) and just assumed it was for RL2.

    I did end up going with the second option you mentioned while in limbo which seemed to work fine. I will read the RelaxedEventMap link you sent.

    Thanks again for the response!

  3. Support Staff 4 Posted by Ondina D.F. on 02 Jul, 2012 02:25 PM

    Ondina D.F.'s Avatar

    You’re welcome!!

    I’m closing the discussion now, but feel free to reopen it in case you have more questions or you need further assistance with this issue.

  4. Ondina D.F. closed this discussion on 02 Jul, 2012 02:25 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