Correct way to pass a payload when Flex 4 States are involved

RJ's Avatar

RJ

11 Sep, 2010 11:27 PM

Let's say we've got a Robotlegs app that lets you graphically browse a file system. In the first state we're looking at a group of folders. Clicking one of those folders will transition us into a view of the files in that folder, which is a different state. This second state needs a reference to the folder object itself for some of the things it does and displays. Each state is a separate view object and has it's own mediator.

My question is, what's the right way to pass that folder to the second state? Normally I'd use an event - dispatch something like a "Folder Selected Event" with the folder as the payload from the first view's mediator. The problem in this case is that since we're using states, the second view hasn't been instantiated yet -- flex 4 uses lazy loading on the state view objects, so the second view object is ABOUT to be instantiated and it's mediator is ABOUT to show up. If I dispatch the event from my first view it will fall on deaf ears.

Another option would be to put it on the model. I don't like this option because this folder isn't something anyone else needs to know about. It's not a state we need to persist or information other components need to know about - it's simply the result of a user selection on a list of folders.

A third option I see is to dispatch the event and pick it up in some other mediator - maybe the app mediator, who can wait until the view object is instantiated and push the folder information down to it. Again, this smells of a bit too much hackery.

How would you guys solve this? Just use the model?

  1. Stray closed this discussion on 12 Feb, 2011 10:57 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