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: AsyncMacroCommand (with a ChainNotifier style Mediator)  (Read 15774 times)
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« on: October 03, 2008, 12:14:16 »

I've looked at the ChainNotifier http://forums.puremvc.org/index.php?topic=422.0 but its not necessarily what I expected. I've been wanting an approach that follows more the PureMVC flow, API... not sure what word I'm looking for here. Looking for something that feels PureMVCish.

@cliff, @binarycrafts

I think I have an idea that will solve some of your concerns that you mentioned in the ChainNotifier utility topic (link above).

I envision say.. an AsyncMarcoCommand, that would implement ICommand and INotifier that you call addSubCommand for each asynchronous command you wanted fired in order. Now before you all cry foul let me explain the handling for these sub commands!

Using something similar to the ChainNotifier, the AsyncMacroCommand would add each sub command to an instance of a AsyncCommandMediator (I can't think of a better name at the moment so don't get to caught up on this one!). This is crucial since Cliff makes a good point that the mediator after being registered will have to be de-registered.

How to handle the de-registration? Well with each addSubCommand call you would add in the notification it sends on complete. The AsyncCommandMediator would know (since its listening for all those notifications) when the last notification fires thus being able to remove itself from the framework.

What does this solve?

1. The command won't have state! Yay!
2. Since a mediator is registered it will handle removing itself from the framework when its done
3. Every time you issue a new AsyncMacroCommand it will always register a new instance of AsyncCommandMediator (and safely deregister when all commands are completed)
4. Sticks to the API the PureMVC framework provides for sequencing commands (only now it works with async ones!)
5. Provides a map.. an easy to read sequence of the commands being fired in one place. No more having to go search for each sendNotification call that triggers the next command. Woo hoo!

Brainstorming this just now what do you guys think? Would something like this work? Say the word and R&D will begin!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 04, 2008, 01:49:22 »

I'm feeling a little wierd about your proposed setup, and its because the responsibilities of the Mediator are being stretched which dilutes its role and meaning within the framework.

Not to keep you frm giving it a whirl, but it just doesn't quite feel right.

-=Cliff>
Logged
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #2 on: October 06, 2008, 12:46:25 »

@Cliff,

I'm curious then what you would suggest that would make it feel better with the rest of the framework? Don't take that as a snotty question, I'm being serious as I really have an interest in making commands work with asynchronous actions but that doesn't deviate away from the API the framework provides for creating and executing commands.

I thought it was a very clever approach with ChainNotifier and figured with some enhancements it could be made to conform to the framework. I agree though its taking the Mediator for something else that doesn't mediate the view. I would use a Proxy here as it would fit (I think at least) but it has no way of receiving replies. I don't think it would work with a Proxy.

Curious to hear your suggestions as its something I really would love for the framework to have and I think others would agree. It would be so nice to have a command that encapsulates all your calls to sub commands that each are asynchronously waiting for a response but fired in order by using the addSubCommand() call just like you would with a sync macro command.

Thoughts?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: October 06, 2008, 04:15:56 »

Believe it or not, just today, Duncan Hall submitted the perfect answer to this problem. It consists of two classes and an interface:

AsyncCommand which extends SimpleCommand
AsyncMacroCommand which extends MacroCommand
IAsyncCommand which extends ICommand

It is the simplest design I can imagine for handling this issue and a darn clean implementation. The AsyncMacroCommand adds ICommands as sub commands.

While the AsyncMacroCommand is executing, if the next sub command implements IASyncCommand, it gives a listener to the IASyncCommand which is called when that IAsyncCommand is complete. (IASyncCommands have a commandComplete() method they call when they are done). Also if the next subcommand to be executed is not an IAsyncCommand, then it just executes it and then goes ahead to the next subcommand immediately. This way an AsyncMacroCommand can have subcommands that are not async, but normal ICommands.

Spiff. Look for it here soon. He is refactoring it into the puremvc package space and it will be available shortly.

And by Ducan a beer if you see him around :)
-=Cliff>
« Last Edit: October 06, 2008, 04:20:01 by puremvc » Logged
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #4 on: October 06, 2008, 04:28:01 »

Excellent! Did he talk to you through email or through a thread? I'd love to test out or start using the utility! How does he handle adding event handlers without adding them to the command thus giving the command state?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: October 06, 2008, 05:27:06 »

The AsyncCommand will end up being used as an IResponder to services, it is inevitable. This is contrary to my original intention of keeping services entirely inside the model region, that's why I didn't have this pattern to begin with.

But the threads on this topic have made it clear this is what people want. No matter how you look at the problem if you want to run a sequence of commands some of which may go away for a bit, either to get input from a user (say in a modal window) or to get data from services you need this if you're not willing to break the problem down to a bunch of notifications. And honestly, that has proven more difficult to manage than it seems. You have to always be mindful of your notification constants and defining understandable protocols for their naming. It helps if you visualise everything as an FSM.

But anyway, the 'state' we're trying to avoid is not given to an AsyncCommand  just because it sets a listener.

True it goes through discrete runtime lifecycle states - executing, waiting, responding and terminating. But the 'bad' kind of state for a command is the kind where it retains values between executions. This doesn't happen so its reasonable to allow this in an AsyncCommand.

In the building of a portable model,(where you build your modelclasses in another project altogether for reuse between multiple apps) you may still include commands, and in fact should have at least one, that registers all the proxies, so that the app only need register and execute that one command to prep the model. That command could register other commands as well, which could communicate with services and manipulate proxies. Good for moving data validation code into as well. (Not flex validators, I mean model integrity logic).

So all in all I look forward to embracing this tool as well. So much so it'll be in the org.puremvc.as3.patterns.command package rather than utilities. That way if best practices with it prove good, it might be promoted directly into the framework and it won't cause anyone to have to migrate code if that happens.

-=Cliff>
Logged
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #6 on: October 09, 2008, 09:18:47 »

Not be pushy Cliff (although I must admit I can be!) any news on when this will be available? I definitely have a real need for it and would love to drop it in even test it out.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: October 09, 2008, 04:49:23 »

Well, I'm expecting to get a bunch of projects in the repo over the weekend. I've got the process started on a bunch of them. This one should go quickly, though, and it'll be worth the wait.

-=Cliff>
Logged
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« Reply #8 on: October 15, 2008, 07:45:57 »

@Cliff,

Hate to bother but the weekend has come and gone. Any status on the async command utility being available for download? I'd be happy to help test it out if you aren't sure yet about putting it up publicly. Let me know. Thanks!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: October 21, 2008, 07:27:55 »

Sorry about that. Several of the projects that should've gone smoothly didn't and the rest of the PureMVC time this weekend got preempted by the availability of someone to help with the site usability issues, such as the forums you are now reading without being jammed into an unbookmarkable IFrame. Shortly the Trac sites will be in the same template as well and using the site won't be such a pain.

This week very little will happen as I prepare for the HEAD web conference talk.

The week before MAX will be free for me and I plan to spend it all on catching up on PureMVC.

Email me directly at and I will send you a copy of the project if you have to have it before then.

-=Cliff>
Logged
philippk
Newbie
*
Posts: 1


View Profile Email
« Reply #10 on: December 09, 2008, 10:16:28 »

hi there,
i tried to integrate the AsyncCommand, but are getting the following error:

:
[Fault] exception, information=TypeError: Error #1006: value is not a Function.
Fault, AsyncCommand.as:42
 42    onComplete();


anyone with an idea why this is?!
the example "Sequential_1_0" is running smoothly.

cheers
phil
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #11 on: December 10, 2008, 06:38:43 »

You have to set an onComplete callback function on IAsyncCommand implementers. This is how they indicate that they've finished their work.

-=Cliff> 
Logged
Pages: [1]
Print