Skip to content

Commit b524671

Browse files
committed
* Fix issue where the setOnComplete method needed to use an arrow function calling this.nextCommand, rather than passing a reference to this.nextCommand, which is a prototype and does not have access to instance data
* Improve nullish checking of this.onComplete * Add index.js to build folder that is copied to the bin folder at build time and is the entry point to the project * Added missing instance property declaration onComplete to AsyncMacroCommand.js
1 parent 4b0cc25 commit b524671

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

bin/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {AsyncCommand, AsyncMacroCommand} from './puremvc-async-command.js';
2+
3+
export {
4+
AsyncCommand,
5+
AsyncMacroCommand
6+
}

bin/puremvc-async-command.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,25 @@ class AsyncMacroCommand extends puremvc.Notifier
161161
*/
162162
nextCommand()
163163
{
164-
if (this.subCommands.length > 0)
164+
if (this.subCommands?.length > 0)
165165
{
166166
const factory = this.subCommands.shift();
167167
const instance = factory();
168168
let isAsync = ( instance?.isAsync === true );
169-
if (isAsync) instance.setOnComplete( this.nextCommand );
169+
if (isAsync) instance.setOnComplete( () => this.nextCommand() );
170170
instance.initializeNotifier( this.multitonKey );
171171
instance.execute( this.note );
172172
if (!isAsync) this.nextCommand();
173173
} else {
174-
if( this.onComplete !== null ) this.onComplete();
175-
this.note = null;
174+
if( this?.onComplete ) this.onComplete();
175+
this.note = null;
176176
this.onComplete = null;
177177
}
178178
}
179179

180180
note; // Notification
181181
subCommands; // Array of command subcommand factories
182+
onComplete; // Optional function to call when the AsyncMacro completes
182183
isAsync = true; // simplest workaround to lack of interfaces
183184
}
184185

bin/puremvc-async-command.min.js

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@puremvc/puremvc-js-util-async-command",
3-
"version": "1.0.2",
3+
"version": "1.0.5",
44
"description": "PureMVC JS MultiCore Async Command Utility",
55
"main": "bin/index.js",
66
"type": "module",
@@ -9,7 +9,7 @@
99
"url": "https://github.com/PureMVC/puremvc-js-util-async-command.git"
1010
},
1111
"scripts": {
12-
"build": "npm run clean && npm run build:lib",
12+
"build": "npm run clean && npm run build:lib && cp build/index.js bin/",
1313
"build:lib": "rollup -c build/rollup.conf.mjs",
1414
"build:doc": "jsdoc -c build/jsdoc.json",
1515
"clean": "rm -rf bin",

src/AsyncMacroCommand.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,24 @@ export class AsyncMacroCommand extends puremvc.Notifier
118118
*/
119119
nextCommand()
120120
{
121-
if (this.subCommands.length > 0)
121+
if (this.subCommands?.length > 0)
122122
{
123123
const factory = this.subCommands.shift();
124124
const instance = factory();
125125
let isAsync = ( instance?.isAsync === true );
126-
if (isAsync) instance.setOnComplete( this.nextCommand );
126+
if (isAsync) instance.setOnComplete( () => this.nextCommand() );
127127
instance.initializeNotifier( this.multitonKey );
128128
instance.execute( this.note );
129129
if (!isAsync) this.nextCommand();
130130
} else {
131-
if( this.onComplete !== null ) this.onComplete();
132-
this.note = null;
131+
if( this?.onComplete ) this.onComplete();
132+
this.note = null;
133133
this.onComplete = null;
134134
}
135135
}
136136

137137
note; // Notification
138138
subCommands; // Array of command subcommand factories
139+
onComplete; // Optional function to call when the AsyncMacro completes
139140
isAsync = true; // simplest workaround to lack of interfaces
140141
}

0 commit comments

Comments
 (0)