Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: async commands, animations, fsm  (Read 7490 times)
midget35
Newbie
*
Posts: 5


View Profile Email
« on: February 04, 2011, 07:43:31 »

Hi guys,

I've been using PureMVC constantly for around 2 years, but often feel like I lack basic understanding of how to use this framework. I encounter problems with how to run asynch commands all the time. I've read every forum post on Asynch tokens, fsm, but I just don't get what I should do when waiting for animations or remote services to complete.

Here's my scenario:
1.  I click a button in one view that sends a notification to a macro command via that view's mediator.
2. said macro command sets off a sub command that asks several mediators to make adjustments to views, and asks one view in particular to commence a simple tween.
3. once that simple tween is complete, I want the execution of the rest of the subcommands to commence again.

That's basically it. Ideally I don't want to send another command saying that an animation is complete, and start off another batch of sub commands or whatever by calling a slightly different macro command that picks up where the last macro command left off. I just want some concept of delay to exist in a command chain and - ideally- to have some juncture where the feedback of an asynch token (or whatever) might determine which one of several sub commands to initiate next.

I would really appreciate any help here :) This is a daily struggle for me lately that I'm sure is easily overcome. Many thanks in advance for any help.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 08, 2011, 05:42:20 »

Don't use the MacroCommand if you want async breaks between the subcommands. The AsyncCommand utility was meant to do this, and some folks use it and report good things with it.

But the approach I advocate is to use the StateMachine Utility to define discrete application states and control the transitions between them.

How does it do this? Well, basically it becomes like the conductor of your orchestra. Commands and Mediators mostly just listen to it, not each other. It is in charge of knowing the current state and what actions can trigger transitions to other states.

So in your example, lets say you're in state FOOING, leaving it you want to do a transition and we'll call that state BARING and then your next state is BAZING, during which you want some more logic to execute.

And...
click a button in one view that sends a notification to a macro command via that view's mediator
Actually, you send a StateMachine.ACTION notification (like DONE_FOOING) (and perhaps carrying a value object representing a form submission) via that view's mediator. This triggers a change to into state BARING, when the StateMachine will send out a custom announcement notification about the specific state change that you can listen for.

Now, have your Mediators listen for this state change and do their view manipulations, and:
[have] one view in particular to commence a simple tween.

During this tween, nothing else is happening because there's no pending logic (subcommands) to execute. The StateMachine is just waiting to hear an action to trigger a state change.

once that simple tween is complete, I want the execution of the rest of the subcommands to commence again.
You send another StateMachine.ACTION notification via the view that was tweening's Mediator (DONE_BARING). The StateMachine knows that this a valid action to transition into the next state BAZING. The rest of the logic that you were going to have run after the async break could be a MacroCommand that listens for the change into state BAZING.

Hope this helps.

-=Cliff>
Logged
midget35
Newbie
*
Posts: 5


View Profile Email
« Reply #2 on: February 10, 2011, 07:48:18 »

Hi Cliff,

Thanks so much for your response :) I will take this onboard and build a trial app with the fsm implementation. I'll report back here on progress.

Thanks again!
Logged
Pages: [1]
Print