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: Port to AsyncCommand - A PureMVC / JS Utility  (Read 7988 times)
saad
Sr. Member
****
Posts: 65


View Profile Email
« on: September 26, 2014, 03:55:37 »

Developed JavaScript Utility for Asynchronous Commands with a demo.

Async Command
https://github.com/sshams/puremvc-js-util-asynccommand

Demo Sequential
https://github.com/sshams/puremvc-js-demo-sequential
« Last Edit: September 29, 2014, 10:24:07 by saad » Logged
saad
Sr. Member
****
Posts: 65


View Profile Email
« Reply #1 on: October 01, 2014, 10:26:13 »

Hi Cliff:

As a test I tried to extend the AsyncMacroCommand Pattern to accommodate adding other AsyncMacroCommands, just like MacroCommand could not only execute SimpleCommands but other MacroCommands as well.

I edited single line in my own local copy to make it work inside AsyncMacroCommand.prototype.nextCommand

var isAsync = commandInstance instanceof puremvc.asynccommand.AsyncCommand || commandInstance instanceof puremvc.asynccommand.AsyncMacroCommand;

It works fine, UberAsyncMacroCommand executes FirstAsyncMacroCommand which executes all of it's sub AsyncCommands in sequence (asynchronously) and then turns to SecondAsyncMacroCommand executing it's series of AsyncCommands (asynchronously) and finally UberAsyncMacroCommand onComplete.

The exception that individual AsyncMacroCommands' onComplete functions are taken over by the Uber AsyncMacroCommand, i.e. no custom onCompleteHandlers for each subAsyncMacroCommands.

any thoughts on this on? or even should we have individual custom onComplete handlers for each subAsyncMacroCommands?
« Last Edit: October 01, 2014, 10:47:56 by saad » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: October 02, 2014, 06:15:05 »

Hi Saad,

Not sure we need onComplete in the sub AsyncMacroCommands if the uber deals with them properly in sequence.

-=Cliff>
Logged
saad
Sr. Member
****
Posts: 65


View Profile Email
« Reply #3 on: October 02, 2014, 08:37:02 »

I think now it's better to design those SubAsyncMacroCommands to perform their operations without a need for their individual onCompleteHandlers, and just handle onComplete within UberAsyncMacroCommand.

Following line works in this case. The book says to program to an interface not to an implementation and your code is checking the command instance against IAsyncCommand but since we don't have something built-in like Interface in JS, we are forced to program to an Implementation. There are JS patterns/utilities out there to emulate interface with type checking but clarity and checking against just two implementations outweighs bringing in extra set of functions.

var isAsync = commandInstance instanceof puremvc.asynccommand.AsyncCommand || commandInstance instanceof puremvc.asynccommand.AsyncMacroCommand;
« Last Edit: October 02, 2014, 09:00:13 by saad » Logged
Pages: [1]
Print