PureMVC Architects Lounge

PureMVC Manifold => Multicore Version => Topic started by: saad on September 26, 2014, 03:55:37



Title: Port to AsyncCommand - A PureMVC / JS Utility
Post by: saad 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


Title: Re: Port to AsyncCommand - A PureMVC / JS Utility
Post by: saad 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?


Title: Re: Port to AsyncCommand - A PureMVC / JS Utility
Post by: puremvc 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>


Title: Re: Port to AsyncCommand - A PureMVC / JS Utility
Post by: saad 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;