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: Asynchronous and State Machine  (Read 6022 times)
gordonp
Newbie
*
Posts: 5


View Profile Email
« on: August 04, 2009, 02:02:41 »

I am having a difficult time getting my head around asynchronous remote service calls.

I think I just need a simple code demo to really get the point. I have reviewed many if not all the Actionscript code samples and haven't found a clear example.

This is the behavior I am looking for

Click a button in a view, trigger an action and notification that calls a proxy and generates a remote service call.

Once the remote service call result event returns, send data back to the application and change one or more views including the view where I clicked the button.

Other variations, on the theme:

Click button --> Make Service Call --> Receive Data back --> Transition to different and updated view.

If no data is returned then provide an alert and don't transition to new view.

And finally, I should add one more requirement. In some cases the service call should be a blocking call. In that while the service is communicating with the server, the view should not be interactive. Perhaps, even display a "processing" view while waiting for the remote service to complete.

Is this best handled by a service proxy and then use the state machine to manage the transitions between views in the app? Is there any any code examples that clearly demonstrate passing around data with the StateMachine?

I have looked at the async command but that doesn't seem to do what I want.

I feel like I have a good grasp of the other features of pureMVC, it is just this asynchronous data transfer that is tripping me up.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 04, 2009, 03:45:33 »

You've got the idea.

When a state specific changed announcement is sent saying you've entered, say, the FETCHING state, have a command respond by invoking a proxy method to fetch.

When the data comes back, have the proxy send a note, say MyProxy.DATA_RETRIEVED, that triggers a command which generates a StateMachine.ACTION notification. If the Proxy passed a reference to the data then the command can include that in the body of the ACTION notification to pass it to the next state, say DISPLAYING.

A mediator interested in the state specific changed announcement for the DISPLAYING state would see the data the Proxy fetched in its note body, and could simply set it on its view component for display.

As for making the view non-interactive while the service is being called, it would be during the entirety of the FETCHING state.

Resist the urge to use the state specific entering and exiting announcements, these are for guard logic only, not setup/teardown of UI. Wait until the state specific changed announcement for the FETCHING state.

The command that we've described above as responding to that by making the proxy call could trigger the UI interaction guard (perhaps a partially opaque box or a modal popup) by sending a notification prior to its invoking the proxy method. And the command that responds to the DATA_RETRIEVED message could also trigger the removal of the UI interaction guard.

Check out the original Sea of Arrows code at http://seaofarrows.com/srcview

You can see data being passed from the STARTING state to the FAILING state in the com.seaofarrows.musicplayer.shell.controller.StartShellCommand and FailCommand classes. It wasn't asynchronously retrieved from a server, but that's irrelevant.

-=Cliff>
Logged
Pages: [1]
Print