Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Welcome, Guest. Please login or register.
August 23, 2017, 06:18:23 PM
Home Help Search Login Register
News: Please DM @puremvc on Twitter to gain forum access. Spambots are why we can't have nice things.
Pages: [1]
Print
Author Topic: Port to AsyncCommand - A PureMVC / JS Utility  (Read 3174 times)
saad
Sr. Member
****
Posts: 65


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

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 AM by saad » Logged
saad
Sr. Member
****
Posts: 65


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

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 PM by saad » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2870



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

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
« Reply #3 on: October 02, 2014, 08:37:02 AM »

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 AM by saad » Logged
Pages: [1]
Print
Jump to: