Skip to content

Commit 8955246

Browse files
committed
Update to use PureMVC 2.0.7 and build for cjs and esm. Updated VERSION to 1.0.6
1 parent 7220835 commit 8955246

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+17997
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ With the `AsyncCommand` and `AsyncMacroCommand` you could dynamically create a p
1212
* [Historical Discussion](http://forums.puremvc.org/index.php?topic=831.0)
1313

1414
## Status
15-
Beta - [Version 1.0.5](https://github.com/PureMVC/puremvc-js-util-async-command/blob/master/VERSION)
15+
Beta - [Version 1.0.6](https://github.com/PureMVC/puremvc-js-util-async-command/blob/master/VERSION)
1616
* TODO: Tests and demos
1717

1818
## Platforms / Technologies

VERSION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PureMVC Async Command Utility for Javascript (Ported)
22
--------------------------------------------------------------------------
3-
Release Date: 3/3/2024
3+
Release Date: 8/29/2024
44
Platform: JavaScript (Native)
55
Version: 1
66
Revision: 0
7-
Minor: 5
7+
Minor: 6
88
Authors: Copyright © 2008 Duncan Hall <duncan.hall@puremvc.org>
99
: Ported in 2024 by Cliff Hall <cliff.hall@puremvc.org>
1010
-------------------------------------------------------------------------
@@ -13,4 +13,5 @@ Release Date: 3/3/2024
1313
1.0.2 Update to latest PureMVC framework
1414
...
1515
1.0.5 Fixed issues with nullish checking and necessary closure in AsyncMacroCommand
16+
1.0.6 Update to use PureMVC 2.0.7 and build for cjs and esm.
1617

bin/cjs/puremvc-async-command.cjs

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
'use strict';
2+
3+
var puremvcJsMulticoreFramework = require('@puremvc/puremvc-js-multicore-framework');
4+
5+
/*
6+
PureMVC MultiCore Utility for JS - AsyncCommand
7+
Copyright(c) 2008 Duncan Hall <duncan.hall@puremvc.org>
8+
2024 Cliff Hall <cliff.hall@puremvc.org>
9+
Your reuse is governed by the Creative Commons Attribution 3.0 License
10+
*/
11+
12+
/**
13+
* A base IAsyncCommand implementation.
14+
*
15+
* Your subclass should override the `execute`
16+
* method where your business logic will handle the <code>Notification</code>. </P>
17+
*
18+
* @see AsyncMacroCommand
19+
*/
20+
class AsyncCommand extends puremvcJsMulticoreFramework.SimpleCommand {
21+
22+
/**
23+
* Registers the callback for a parent <code>AsyncMacroCommand</code>.
24+
*
25+
* @param callback The <code>AsyncMacroCommand</code> method to call on completion
26+
*/
27+
setOnComplete ( callback )
28+
{
29+
this.onComplete = callback;
30+
}
31+
32+
/**
33+
* Notify the parent AsyncMacroCommand that this command is complete.
34+
*
35+
* Call this method from your subclass to signify that your asynchronous
36+
* command has finished.
37+
*/
38+
commandComplete()
39+
{
40+
this.onComplete();
41+
}
42+
43+
onComplete; // the callback to invoke on command completion
44+
isAsync = true; // simplest workaround to lack of interfaces
45+
}
46+
47+
/*
48+
PureMVC MultiCore Utility for JS - AsyncCommand
49+
Copyright(c) 2008 Duncan Hall <duncan.hall@puremvc.org>
50+
2024 Cliff Hall <cliff.hall@puremvc.org>
51+
Your reuse is governed by the Creative Commons Attribution 3.0 License
52+
*/
53+
54+
/**
55+
* A base Command implementation that executes other
56+
* Commands asynchronously.
57+
58+
* An AsyncMacroCommand maintains a list of
59+
* factories that create SubCommands.
60+
61+
* When execute is called, the AsyncMacroCommand
62+
* caches a reference to the Notification and calls
63+
* nextCommand.
64+
65+
* If there are still SubCommands to be executed,
66+
* the nextCommand method instantiates and calls
67+
* execute on each of its SubCommands in turn.
68+
*
69+
* Each SubCommand will be passed a reference to the
70+
* original Notification that was passed to the
71+
* AsyncMacroCommand's execute method. If the
72+
* SubCommand to execute is an IAsyncCommand, the
73+
* next SubCommand will not be executed until the
74+
* previousAsyncCommand has called its commandComplete
75+
* method.
76+
77+
* Unlike AsyncCommand and SimpleCommand, your subclass
78+
* should not override execute, but instead, should
79+
* override the initializeAsyncMacroCommand method,
80+
* calling addSubCommand once for each SubCommand
81+
* to be executed.
82+
*
83+
* @see AsyncCommand
84+
*/
85+
class AsyncMacroCommand extends puremvcJsMulticoreFramework.Notifier
86+
{
87+
88+
/**
89+
* Constructor.
90+
91+
* You should not need to define a constructor,
92+
* instead, override the initializeAsyncMacroCommand
93+
* method.
94+
95+
* If your subclass does define a constructor, be
96+
* sure to call super().
97+
*/
98+
constructor()
99+
{
100+
super();
101+
this.subCommands = [];
102+
this.initializeAsyncMacroCommand();
103+
}
104+
105+
/**
106+
* Initialize the AsyncMacroCommand.
107+
*
108+
* In your subclass, override this method to
109+
* initialize the AsyncMacroCommand's SubCommand
110+
* list with factories like this:
111+
*
112+
* // Initialize MyMacroCommand
113+
* function initializeAsyncMacroCommand()
114+
* {
115+
* addSubCommand( () => new FirstCommand );
116+
* addSubCommand( () => new SecondCommand );
117+
* addSubCommand( () => new ThirdCommand );
118+
* }
119+
*
120+
* SubCommands should extend one of the following
121+
* - AsyncMacroCommand
122+
* - AsyncCommand
123+
* - MacroCommand
124+
* - SimpleCommand
125+
*/
126+
initializeAsyncMacroCommand(){}
127+
128+
/**
129+
* Add a SubCommand.
130+
*
131+
* The SubCommands will be called in First In/First Out (FIFO)
132+
* order.
133+
*
134+
* @param factory a function that instantiates the subcommand
135+
*/
136+
addSubCommand( factory ) { this.subCommands.push( factory );}
137+
138+
/**
139+
* Registers the callback for a parent AsyncMacroCommand.
140+
*
141+
* @param callback The AsyncMacroCommand method to call on completion
142+
*/
143+
setOnComplete ( callback ) { this.onComplete = callback; }
144+
145+
/**
146+
* Starts execution of this AsyncMacroCommand's SubCommands.
147+
*
148+
* The SubCommands will be called in First In/First Out (FIFO) order.
149+
*
150+
* @param notification the Notification object to be passed to each SubCommand.
151+
*/
152+
execute( notification )
153+
{
154+
this.note = notification;
155+
this.nextCommand();
156+
}
157+
158+
/**
159+
* Execute this AsyncMacroCommand's next SubCommand.
160+
*
161+
* If the next SubCommand is asynchronous, a callback is registered for
162+
* the command completion, else the next command is run.
163+
*/
164+
nextCommand()
165+
{
166+
if (this.subCommands?.length > 0)
167+
{
168+
const factory = this.subCommands.shift();
169+
const instance = factory();
170+
let isAsync = ( instance?.isAsync === true );
171+
if (isAsync) instance.setOnComplete( () => this.nextCommand() );
172+
instance.initializeNotifier( this.multitonKey );
173+
instance.execute( this.note );
174+
if (!isAsync) this.nextCommand();
175+
} else {
176+
if( this?.onComplete ) this.onComplete();
177+
this.note = null;
178+
this.onComplete = null;
179+
}
180+
}
181+
182+
note; // Notification
183+
subCommands; // Array of command subcommand factories
184+
onComplete; // Optional function to call when the AsyncMacro completes
185+
isAsync = true; // simplest workaround to lack of interfaces
186+
}
187+
188+
exports.AsyncCommand = AsyncCommand;
189+
exports.AsyncMacroCommand = AsyncMacroCommand;

bin/cjs/puremvc-async-command.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/cjs/puremvc-async-command.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/puremvc-async-command.js renamed to bin/esm/puremvc-async-command.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { puremvc } from '@puremvc/puremvc-js-multicore-framework';
1+
import { SimpleCommand, Notifier } from '@puremvc/puremvc-js-multicore-framework';
22

33
/*
44
PureMVC MultiCore Utility for JS - AsyncCommand
@@ -15,7 +15,7 @@ import { puremvc } from '@puremvc/puremvc-js-multicore-framework';
1515
*
1616
* @see AsyncMacroCommand
1717
*/
18-
class AsyncCommand extends puremvc.SimpleCommand {
18+
class AsyncCommand extends SimpleCommand {
1919

2020
/**
2121
* Registers the callback for a parent <code>AsyncMacroCommand</code>.
@@ -80,7 +80,7 @@ class AsyncCommand extends puremvc.SimpleCommand {
8080
*
8181
* @see AsyncCommand
8282
*/
83-
class AsyncMacroCommand extends puremvc.Notifier
83+
class AsyncMacroCommand extends Notifier
8484
{
8585

8686
/**
@@ -108,7 +108,7 @@ class AsyncMacroCommand extends puremvc.Notifier
108108
* list with factories like this:
109109
*
110110
* // Initialize MyMacroCommand
111-
* override protected function initializeAsyncMacroCommand() : void
111+
* function initializeAsyncMacroCommand()
112112
* {
113113
* addSubCommand( () => new FirstCommand );
114114
* addSubCommand( () => new SecondCommand );

bin/esm/puremvc-async-command.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)