Skip to content

Commit

Permalink
* Fix issue where the setOnComplete method needed to use an arrow fun…
Browse files Browse the repository at this point in the history
…ction 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
  • Loading branch information
cliffhall committed Mar 5, 2024
1 parent 4b0cc25 commit b524671
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {AsyncCommand, AsyncMacroCommand} from './puremvc-async-command.js';

export {
AsyncCommand,
AsyncMacroCommand
}
9 changes: 5 additions & 4 deletions bin/puremvc-async-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,25 @@ class AsyncMacroCommand extends puremvc.Notifier
*/
nextCommand()
{
if (this.subCommands.length > 0)
if (this.subCommands?.length > 0)
{
const factory = this.subCommands.shift();
const instance = factory();
let isAsync = ( instance?.isAsync === true );
if (isAsync) instance.setOnComplete( this.nextCommand );
if (isAsync) instance.setOnComplete( () => this.nextCommand() );
instance.initializeNotifier( this.multitonKey );
instance.execute( this.note );
if (!isAsync) this.nextCommand();
} else {
if( this.onComplete !== null ) this.onComplete();
this.note = null;
if( this?.onComplete ) this.onComplete();
this.note = null;
this.onComplete = null;
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion bin/puremvc-async-command.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@puremvc/puremvc-js-util-async-command",
"version": "1.0.2",
"version": "1.0.5",
"description": "PureMVC JS MultiCore Async Command Utility",
"main": "bin/index.js",
"type": "module",
Expand All @@ -9,7 +9,7 @@
"url": "https://github.com/PureMVC/puremvc-js-util-async-command.git"
},
"scripts": {
"build": "npm run clean && npm run build:lib",
"build": "npm run clean && npm run build:lib && cp build/index.js bin/",
"build:lib": "rollup -c build/rollup.conf.mjs",
"build:doc": "jsdoc -c build/jsdoc.json",
"clean": "rm -rf bin",
Expand Down
9 changes: 5 additions & 4 deletions src/AsyncMacroCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,24 @@ export class AsyncMacroCommand extends puremvc.Notifier
*/
nextCommand()
{
if (this.subCommands.length > 0)
if (this.subCommands?.length > 0)
{
const factory = this.subCommands.shift();
const instance = factory();
let isAsync = ( instance?.isAsync === true );
if (isAsync) instance.setOnComplete( this.nextCommand );
if (isAsync) instance.setOnComplete( () => this.nextCommand() );
instance.initializeNotifier( this.multitonKey );
instance.execute( this.note );
if (!isAsync) this.nextCommand();
} else {
if( this.onComplete !== null ) this.onComplete();
this.note = null;
if( this?.onComplete ) this.onComplete();
this.note = null;
this.onComplete = null;
}
}

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

0 comments on commit b524671

Please sign in to comment.