diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..52379b0
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,63 @@
+on:
+ push:
+ branches:
+ - main
+
+ pull_request:
+ release:
+ types: [published]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-node@v4
+ with:
+ node-version-file: package.json
+ cache: npm
+
+ # Working around https://github.com/npm/cli/issues/4828
+ # - run: npm ci
+ - run: npm install --no-package-lock
+
+ - name: Check formatting
+ run: npm run format:check
+
+ - name: Check syntax
+ run: npm run lint
+
+ - name: Check types
+ run: npm run typecheck
+
+ - name: Run tests
+ run: npm test
+
+ - run: npm run build
+
+ publish:
+ runs-on: ubuntu-latest
+ if: github.event_name == 'release'
+ needs: build
+
+ permissions:
+ contents: read
+ id-token: write
+
+ steps:
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
+ with:
+ node-version-file: package.json
+ cache: npm
+ registry-url: "https://registry.npmjs.org"
+
+ # Working around https://github.com/npm/cli/issues/4828
+ # - run: npm ci
+ - run: npm install --no-package-lock
+
+ - run: npm run npm:publish:dry-run
+
+ - run: npm run npm:publish
diff --git a/.gitignore b/.gitignore
index 0831864..4f66e43 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
.idea
.goose
-.goosehints
+.bin
coverage
node_modules
diff --git a/bin/cjs/command/AsyncCommand.js b/bin/cjs/command/AsyncCommand.js
deleted file mode 100644
index f68b335..0000000
--- a/bin/cjs/command/AsyncCommand.js
+++ /dev/null
@@ -1,38 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.AsyncCommand = void 0;
-const puremvc_typescript_multicore_framework_1 = require("@puremvc/puremvc-typescript-multicore-framework");
-/**
- * A base IAsyncCommand implementation.
- *
- *
- * Your subclass should override the execute
- * method where your business logic will handle the INotification.
AsyncMacroCommand.
- *
- * @param value The AsyncMacroCommand method to call on completion
- */
- setOnComplete(value) {
- this.onComplete = value;
- }
- /**
- * Notify the parent AsyncMacroCommand that this command is complete.
- * - * Call this method from your subclass to signify that your asynchronous command - * has finished.
- */ - commandComplete() { - if (this.onComplete) - this.onComplete(); - } -} -exports.AsyncCommand = AsyncCommand; diff --git a/bin/cjs/command/AsyncMacroCommand.js b/bin/cjs/command/AsyncMacroCommand.js deleted file mode 100644 index cd26e44..0000000 --- a/bin/cjs/command/AsyncMacroCommand.js +++ /dev/null @@ -1,147 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.AsyncMacroCommand = void 0; -const AsyncCommand_1 = require("./AsyncCommand"); -const puremvc_typescript_multicore_framework_1 = require("@puremvc/puremvc-typescript-multicore-framework"); -/** - * A baseICommand implementation that executes other
- * ICommands asynchronously.
- *
- *
- * An AsyncMacroCommand maintains a list of
- * ICommand Class references called SubCommands.
- * When execute is called, the AsyncMacroCommand
- * caches a reference to the INotification and calls
- * nextCommand.
- * If there are still SubCommands's to be executed,
- * the nextCommand method instantiates and calls execute
- * on each of its SubCommands in turn. Each SubCommand will be passed
- * a reference to the original INotification that was passed to the
- * AsyncMacroCommand's execute method. If the
- * SubCommand to execute is an IAsyncCommand, the
- * next SubCommand will not be executed until the previous
- * IAsyncCommand has called its commandComplete method.
- * Unlike AsyncCommand and SimpleCommand, your subclass
- * should not override execute, but instead, should
- * override the initializeAsyncMacroCommand method,
- * calling addSubCommand once for each SubCommand
- * to be executed.
- * You should not need to define a constructor,
- * instead, override the initializeAsyncMacroCommand
- * method.
- * If your subclass does define a constructor, be
- * sure to call super().
AsyncMacroCommand.
- *
- *
- * In your subclass, override this method to
- * initialize the AsyncMacroCommand's SubCommand
- * list with ICommand class references.
- *
- * Note that SubCommands may be any ICommand implementor,
- * AsyncMacroCommands, AsyncCommands,
- * MacroCommands or SimpleCommands are all acceptable.
- */
- initializeAsyncMacroCommand() { }
- /**
- * Add a SubCommand.
- *
- * The SubCommands will be called in First In/First Out (FIFO) - * order.
- * - * @param factory a factory that returns an instance that implementsICommand.
- */
- addSubCommand(factory) {
- this.subCommands.push(factory);
- }
- /**
- * Registers the callback for a parent AsyncMacroCommand.
- *
- * @param value The AsyncMacroCommand method to call on completion
- */
- setOnComplete(value) {
- this.onComplete = value;
- }
- /**
- * Starts execution of this AsyncMacroCommand's SubCommands.
- *
- * - * The SubCommands will be called in First In/First Out (FIFO) order. - *
- * - * @param notification theINotification object to be passsed to each SubCommand.
- */
- execute(notification) {
- this.note = notification;
- this.nextCommand();
- }
- /**
- * Execute this AsyncMacroCommand's next SubCommand.
- *
- * - * If the next SubCommand is asynchronous, a callback is registered for - * the command completion, else the next command is run.
- */ - nextCommand() { - if (this.subCommands.length > 0) { - const factory = this.subCommands.shift(); - const commandInstance = factory(); - const isAsync = commandInstance instanceof AsyncMacroCommand || - commandInstance instanceof AsyncCommand_1.AsyncCommand; - if (isAsync) { - commandInstance.setOnComplete(() => this.nextCommand()); - } - commandInstance.initializeNotifier(this.multitonKey); - if (this.note) - commandInstance.execute(this.note); - if (!isAsync) - this.nextCommand(); - } - else { - if (this.onComplete !== null) - this.onComplete(); - this.note = null; - this.onComplete = null; - } - } -} -exports.AsyncMacroCommand = AsyncMacroCommand; diff --git a/bin/cjs/index.js b/bin/cjs/index.js deleted file mode 100644 index cf9284a..0000000 --- a/bin/cjs/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.AsyncMacroCommand = exports.AsyncCommand = void 0; -var AsyncCommand_1 = require("./command/AsyncCommand"); -Object.defineProperty(exports, "AsyncCommand", { enumerable: true, get: function () { return AsyncCommand_1.AsyncCommand; } }); -var AsyncMacroCommand_1 = require("./command/AsyncMacroCommand"); -Object.defineProperty(exports, "AsyncMacroCommand", { enumerable: true, get: function () { return AsyncMacroCommand_1.AsyncMacroCommand; } }); diff --git a/bin/cjs/package.json b/bin/cjs/package.json deleted file mode 100644 index b731bd6..0000000 --- a/bin/cjs/package.json +++ /dev/null @@ -1 +0,0 @@ -{"type": "commonjs"} diff --git a/bin/esm/command/AsyncCommand.js b/bin/esm/command/AsyncCommand.js deleted file mode 100644 index 0ad1666..0000000 --- a/bin/esm/command/AsyncCommand.js +++ /dev/null @@ -1,34 +0,0 @@ -import { SimpleCommand } from "@puremvc/puremvc-typescript-multicore-framework"; -/** - * A baseIAsyncCommand implementation.
- *
- *
- * Your subclass should override the execute
- * method where your business logic will handle the INotification.
AsyncMacroCommand.
- *
- * @param value The AsyncMacroCommand method to call on completion
- */
- setOnComplete(value) {
- this.onComplete = value;
- }
- /**
- * Notify the parent AsyncMacroCommand that this command is complete.
- * - * Call this method from your subclass to signify that your asynchronous command - * has finished.
- */ - commandComplete() { - if (this.onComplete) - this.onComplete(); - } -} diff --git a/bin/esm/command/AsyncMacroCommand.js b/bin/esm/command/AsyncMacroCommand.js deleted file mode 100644 index ffd5002..0000000 --- a/bin/esm/command/AsyncMacroCommand.js +++ /dev/null @@ -1,143 +0,0 @@ -import { AsyncCommand } from "./AsyncCommand"; -import { Notifier, } from "@puremvc/puremvc-typescript-multicore-framework"; -/** - * A baseICommand implementation that executes other
- * ICommands asynchronously.
- *
- *
- * An AsyncMacroCommand maintains a list of
- * ICommand Class references called SubCommands.
- * When execute is called, the AsyncMacroCommand
- * caches a reference to the INotification and calls
- * nextCommand.
- * If there are still SubCommands's to be executed,
- * the nextCommand method instantiates and calls execute
- * on each of its SubCommands in turn. Each SubCommand will be passed
- * a reference to the original INotification that was passed to the
- * AsyncMacroCommand's execute method. If the
- * SubCommand to execute is an IAsyncCommand, the
- * next SubCommand will not be executed until the previous
- * IAsyncCommand has called its commandComplete method.
- * Unlike AsyncCommand and SimpleCommand, your subclass
- * should not override execute, but instead, should
- * override the initializeAsyncMacroCommand method,
- * calling addSubCommand once for each SubCommand
- * to be executed.
- * You should not need to define a constructor,
- * instead, override the initializeAsyncMacroCommand
- * method.
- * If your subclass does define a constructor, be
- * sure to call super().
AsyncMacroCommand.
- *
- *
- * In your subclass, override this method to
- * initialize the AsyncMacroCommand's SubCommand
- * list with ICommand class references.
- *
- * Note that SubCommands may be any ICommand implementor,
- * AsyncMacroCommands, AsyncCommands,
- * MacroCommands or SimpleCommands are all acceptable.
- */
- initializeAsyncMacroCommand() { }
- /**
- * Add a SubCommand.
- *
- * The SubCommands will be called in First In/First Out (FIFO) - * order.
- * - * @param factory a factory that returns an instance that implementsICommand.
- */
- addSubCommand(factory) {
- this.subCommands.push(factory);
- }
- /**
- * Registers the callback for a parent AsyncMacroCommand.
- *
- * @param value The AsyncMacroCommand method to call on completion
- */
- setOnComplete(value) {
- this.onComplete = value;
- }
- /**
- * Starts execution of this AsyncMacroCommand's SubCommands.
- *
- * - * The SubCommands will be called in First In/First Out (FIFO) order. - *
- * - * @param notification theINotification object to be passsed to each SubCommand.
- */
- execute(notification) {
- this.note = notification;
- this.nextCommand();
- }
- /**
- * Execute this AsyncMacroCommand's next SubCommand.
- *
- * - * If the next SubCommand is asynchronous, a callback is registered for - * the command completion, else the next command is run.
- */ - nextCommand() { - if (this.subCommands.length > 0) { - const factory = this.subCommands.shift(); - const commandInstance = factory(); - const isAsync = commandInstance instanceof AsyncMacroCommand || - commandInstance instanceof AsyncCommand; - if (isAsync) { - commandInstance.setOnComplete(() => this.nextCommand()); - } - commandInstance.initializeNotifier(this.multitonKey); - if (this.note) - commandInstance.execute(this.note); - if (!isAsync) - this.nextCommand(); - } - else { - if (this.onComplete !== null) - this.onComplete(); - this.note = null; - this.onComplete = null; - } - } -} diff --git a/bin/esm/index.js b/bin/esm/index.js deleted file mode 100644 index 1c1431e..0000000 --- a/bin/esm/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export { AsyncCommand } from "./command/AsyncCommand"; -export { AsyncMacroCommand } from "./command/AsyncMacroCommand"; diff --git a/bin/esm/package.json b/bin/esm/package.json deleted file mode 100644 index 6990891..0000000 --- a/bin/esm/package.json +++ /dev/null @@ -1 +0,0 @@ -{"type": "module"} diff --git a/bin/types/command/AsyncCommand.d.ts b/bin/types/command/AsyncCommand.d.ts deleted file mode 100644 index 5cfbc4a..0000000 --- a/bin/types/command/AsyncCommand.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { IAsyncCommand } from "../interfaces/IAsyncCommand"; -import { SimpleCommand } from "@puremvc/puremvc-typescript-multicore-framework"; -/** - * A baseIAsyncCommand implementation.
- *
- *
- * Your subclass should override the execute
- * method where your business logic will handle the INotification.
AsyncMacroCommand.
- *
- * @param value The AsyncMacroCommand method to call on completion
- */
- setOnComplete(value: () => void): void;
- /**
- * Notify the parent AsyncMacroCommand that this command is complete.
- * - * Call this method from your subclass to signify that your asynchronous command - * has finished.
- */ - protected commandComplete(): void; - private onComplete; -} diff --git a/bin/types/command/AsyncMacroCommand.d.ts b/bin/types/command/AsyncMacroCommand.d.ts deleted file mode 100644 index 322a8d2..0000000 --- a/bin/types/command/AsyncMacroCommand.d.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { IAsyncCommand } from "../interfaces/IAsyncCommand"; -import { ICommand, INotification, INotifier, Notifier } from "@puremvc/puremvc-typescript-multicore-framework"; -/** - * A baseICommand implementation that executes other
- * ICommands asynchronously.
- *
- *
- * An AsyncMacroCommand maintains a list of
- * ICommand Class references called SubCommands.
- * When execute is called, the AsyncMacroCommand
- * caches a reference to the INotification and calls
- * nextCommand.
- * If there are still SubCommands's to be executed,
- * the nextCommand method instantiates and calls execute
- * on each of its SubCommands in turn. Each SubCommand will be passed
- * a reference to the original INotification that was passed to the
- * AsyncMacroCommand's execute method. If the
- * SubCommand to execute is an IAsyncCommand, the
- * next SubCommand will not be executed until the previous
- * IAsyncCommand has called its commandComplete method.
- * Unlike AsyncCommand and SimpleCommand, your subclass
- * should not override execute, but instead, should
- * override the initializeAsyncMacroCommand method,
- * calling addSubCommand once for each SubCommand
- * to be executed.
- * You should not need to define a constructor,
- * instead, override the initializeAsyncMacroCommand
- * method.
- * If your subclass does define a constructor, be
- * sure to call super().
AsyncMacroCommand.
- *
- *
- * In your subclass, override this method to
- * initialize the AsyncMacroCommand's SubCommand
- * list with ICommand class references.
- *
- * Note that SubCommands may be any ICommand implementor,
- * AsyncMacroCommands, AsyncCommands,
- * MacroCommands or SimpleCommands are all acceptable.
- */
- protected initializeAsyncMacroCommand(): void;
- /**
- * Add a SubCommand.
- *
- * The SubCommands will be called in First In/First Out (FIFO) - * order.
- * - * @param factory a factory that returns an instance that implementsICommand.
- */
- protected addSubCommand(factory: () => ICommand): void;
- /**
- * Registers the callback for a parent AsyncMacroCommand.
- *
- * @param value The AsyncMacroCommand method to call on completion
- */
- setOnComplete(value: () => void): void;
- /**
- * Starts execution of this AsyncMacroCommand's SubCommands.
- *
- * - * The SubCommands will be called in First In/First Out (FIFO) order. - *
- * - * @param notification theINotification object to be passsed to each SubCommand.
- */
- execute(notification: INotification): void;
- /**
- * Execute this AsyncMacroCommand's next SubCommand.
- *
- * - * If the next SubCommand is asynchronous, a callback is registered for - * the command completion, else the next command is run.
- */ - protected nextCommand(): void; - private subCommands; - private note; - private onComplete; -} diff --git a/bin/types/index.d.ts b/bin/types/index.d.ts deleted file mode 100644 index ba2141b..0000000 --- a/bin/types/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { AsyncCommand } from "./command/AsyncCommand"; -export { AsyncMacroCommand } from "./command/AsyncMacroCommand"; -export type { IAsyncCommand } from "./interfaces/IAsyncCommand"; diff --git a/bin/types/interfaces/IAsyncCommand.d.ts b/bin/types/interfaces/IAsyncCommand.d.ts deleted file mode 100644 index a34c3f1..0000000 --- a/bin/types/interfaces/IAsyncCommand.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ICommand } from "@puremvc/puremvc-typescript-multicore-framework"; -/** - * Interface for an Asynchronous Command. - */ -export interface IAsyncCommand extends ICommand { - /** - * Registers the callback for a parentAsyncMacroCommand.
- *
- * @param value The AsyncMacroCommand method to call on completion
- */
- setOnComplete(value: () => void): void;
-}
diff --git a/package.json b/package.json
index 19944be..ab43182 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
"version": "1.0.2",
"description": "PureMVC AsyncCommand Utility for TypeScript",
"main": "./bin/cjs/index.js",
- "module": "bin/esm/command/index.js",
+ "module": "bin/esm/index.js",
"exports": {
".": {
"import": {
@@ -27,12 +27,13 @@
"scripts": {
"build": "npm run clean && npm run build:lib",
"test": "jest --coverage",
- "lint": "eslint ./src",
- "lint:fix": "eslint ./src --fix",
- "format": "prettier --write ./src",
- "npm:publish:dry-run": "npm publish --dry-run",
- "npm:publish": "npm publish --access public",
- "typecheck": "tsc --noEmit -p tsconfig.json --composite false",
+ "lint": "eslint ./src ./test",
+ "lint:fix": "eslint ./src ./test --fix",
+ "typecheck": "tsc --noEmit -p tsconfig.json --composite false",
+ "format:check": "prettier --check ./src ./test",
+ "format:fix": "prettier --write ./src ./test",
+ "npm:publish:dry-run": "npm publish --dry-run",
+ "npm:publish": "npm publish --access public",
"build:lib": "npm run build:cjs && npm run build:esm",
"build:esm": "tsc --module esnext --outDir bin/esm && echo '{\"type\": \"module\"}' > bin/esm/package.json && rm -rf bin/esm/interfaces",
"build:cjs": "tsc --module commonjs --outDir bin/cjs && echo '{\"type\": \"commonjs\"}' > bin/cjs/package.json && rm -rf bin/cjs/interfaces",
@@ -69,7 +70,7 @@
"license": "BSD-3-Clause",
"directories": {
"doc": "docs",
- "test": "test",
+ "test": "src/test",
"bin": "bin"
},
"dependencies": {
@@ -92,5 +93,8 @@
"typedoc": "^0.27.8",
"typescript-eslint": "^8.25.0",
"zod": "^3.24.2"
+ },
+ "engines": {
+ "node": ">=20"
}
}
diff --git a/src/index.ts b/src/index.ts
index 915af12..ba2141b 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,5 +1,3 @@
export { AsyncCommand } from "./command/AsyncCommand";
export { AsyncMacroCommand } from "./command/AsyncMacroCommand";
export type { IAsyncCommand } from "./interfaces/IAsyncCommand";
-
-
diff --git a/test/AsyncCommand.spec.ts b/test/AsyncCommand.spec.ts
index 61b831e..9de1a2d 100644
--- a/test/AsyncCommand.spec.ts
+++ b/test/AsyncCommand.spec.ts
@@ -1,14 +1,15 @@
-import { INotification, Notification } from "@puremvc/puremvc-typescript-multicore-framework";
+import {
+ INotification,
+ Notification,
+} from "@puremvc/puremvc-typescript-multicore-framework";
import { AsyncCommand } from "../src";
class AsyncCommandTestVO {
-
- public input: number;
- public result: number;
- constructor(input: number) {
- this.input = input;
- this.result = 0;
- }
-
+ public input: number;
+ public result: number;
+ constructor(input: number) {
+ this.input = input;
+ this.result = 0;
+ }
}
/**
* Test the PureMVC SimpleCommand class.
@@ -17,45 +18,39 @@ class AsyncCommandTestVO {
* @see AsyncCommandTestCommand
*/
describe("AsyncCommandTest", () => {
+ /**
+ * Tests the `execute` method of an `AsyncCommand`.
+ *
+ * This test creates a new `Notification`, adding a
+ * `AsyncCommandTestVO` as the body.
+ * It then creates a `AsyncCommandTestCommand` and invokes
+ * its `execute` method, passing in the note.
+ *
+ * Success is determined by evaluating a property on the
+ * object that was passed on the Notification body, which will
+ * be modified by the AsyncCommand.
+ */
+ test("testAsyncCommandExecute", () => {
+ class AsyncCommandTestCommand extends AsyncCommand {
+ execute(notification: INotification): void {
+ const vo: AsyncCommandTestVO = notification.body as AsyncCommandTestVO;
+ vo.result = vo.input * vo.input;
+ }
+ }
- /**
- * Tests the `execute` method of an `AsyncCommand`.
- *
- * This test creates a new `Notification`, adding a
- * `AsyncCommandTestVO` as the body.
- * It then creates a `AsyncCommandTestCommand` and invokes
- * its `execute` method, passing in the note.
- *
- * Success is determined by evaluating a property on the
- * object that was passed on the Notification body, which will
- * be modified by the AsyncCommand.
- */
- test("testAsyncCommandExecute", () => {
-
- class AsyncCommandTestCommand extends AsyncCommand {
-
- execute(notification: INotification): void {
- const vo: AsyncCommandTestVO = notification.body as AsyncCommandTestVO;
- vo.result = vo.input * vo.input;
- }
-
- }
-
- // Create the VO
- const vo = new AsyncCommandTestVO(5);
-
- // Create the Notification (note)
- const notification = new Notification("AsyncCommandTestNote", vo);
-
- // Create the AsyncCommand
- const command = new AsyncCommandTestCommand();
+ // Create the VO
+ const vo = new AsyncCommandTestVO(5);
- // Execute the AsyncCommand
- command.execute(notification);
+ // Create the Notification (note)
+ const notification = new Notification("AsyncCommandTestNote", vo);
- // test assertions
- expect(vo.result).toBe(25);
+ // Create the AsyncCommand
+ const command = new AsyncCommandTestCommand();
- });
+ // Execute the AsyncCommand
+ command.execute(notification);
+ // test assertions
+ expect(vo.result).toBe(25);
+ });
});
diff --git a/test/AsyncMacroCommand.spec.ts b/test/AsyncMacroCommand.spec.ts
index fe0a754..5dfaa6d 100644
--- a/test/AsyncMacroCommand.spec.ts
+++ b/test/AsyncMacroCommand.spec.ts
@@ -1,14 +1,15 @@
-import { INotification, Notification } from '@puremvc/puremvc-typescript-multicore-framework'
-import { AsyncMacroCommand, AsyncCommand } from '../src';
+import {
+ INotification,
+ Notification,
+} from "@puremvc/puremvc-typescript-multicore-framework";
+import { AsyncMacroCommand, AsyncCommand } from "../src";
class AsyncCommandTestVO {
-
- public input: number;
- public result: number;
- constructor(input: number) {
- this.input = input;
- this.result = 0;
- }
-
+ public input: number;
+ public result: number;
+ constructor(input: number) {
+ this.input = input;
+ this.result = 0;
+ }
}
/**
* Test the PureMVC AsyncMacroCommand class.
@@ -16,92 +17,88 @@ class AsyncCommandTestVO {
* @see AsyncMacroCommand
*/
describe("AsyncMacroCommandTest", () => {
-
- test("testExecuteWithSubCommands", done => {
- class TestAsyncCommand1 extends AsyncCommand {
- override execute(note: INotification) {
- setTimeout(() => {
- const vo:AsyncCommandTestVO = note.body;
- vo.result = vo.input * 2;
- this.commandComplete();
- }, 1000);
- }
- }
-
- class TestAsyncCommand2 extends AsyncCommand {
- override execute(note: INotification) {
- setTimeout(() => {
- const vo:AsyncCommandTestVO = note.body;
- vo.result = (vo.result as number) * 2;
- this.commandComplete();
- }, 1000);
- }
- }
-
- class TestAsyncMacroCommand extends AsyncMacroCommand {
- protected override initializeAsyncMacroCommand(): void {
- this.addSubCommand(() => new TestAsyncCommand1());
- this.addSubCommand(() => new TestAsyncCommand2());
- }
- }
-
- const vo = new AsyncCommandTestVO(5);
- const asyncMacroCommand = new TestAsyncMacroCommand()
- const notification = new Notification("TestNotification", vo)
- asyncMacroCommand.execute(notification)
+ test("testExecuteWithSubCommands", (done) => {
+ class TestAsyncCommand1 extends AsyncCommand {
+ override execute(note: INotification) {
setTimeout(() => {
- expect(vo.input).toEqual(5)
- expect(vo.result).toEqual(20)
- done()
- }, 3000);
+ const vo: AsyncCommandTestVO = note.body;
+ vo.result = vo.input * 2;
+ this.commandComplete();
+ }, 1000);
+ }
+ }
- });
+ class TestAsyncCommand2 extends AsyncCommand {
+ override execute(note: INotification) {
+ setTimeout(() => {
+ const vo: AsyncCommandTestVO = note.body;
+ vo.result = (vo.result as number) * 2;
+ this.commandComplete();
+ }, 1000);
+ }
+ }
- test("testSetOnComplete", done => {
- class TestAsyncCommand1 extends AsyncCommand {
- override execute(note: INotification) {
- setTimeout(() => {
- const vo:AsyncCommandTestVO = note.body;
- vo.result = vo.input * vo.input;
- this.commandComplete();
- }, 1000);
- }
- }
+ class TestAsyncMacroCommand extends AsyncMacroCommand {
+ protected override initializeAsyncMacroCommand(): void {
+ this.addSubCommand(() => new TestAsyncCommand1());
+ this.addSubCommand(() => new TestAsyncCommand2());
+ }
+ }
- class TestAsyncCommand2 extends AsyncCommand {
- override execute(note: INotification) {
- setTimeout(() => {
- const vo:AsyncCommandTestVO = note.body;
- vo.result = vo.result * vo.input;
- this.commandComplete();
- }, 1000);
- }
- }
+ const vo = new AsyncCommandTestVO(5);
+ const asyncMacroCommand = new TestAsyncMacroCommand();
+ const notification = new Notification("TestNotification", vo);
+ asyncMacroCommand.execute(notification);
+ setTimeout(() => {
+ expect(vo.input).toEqual(5);
+ expect(vo.result).toEqual(20);
+ done();
+ }, 3000);
+ });
- class TestAsyncMacroCommand extends AsyncMacroCommand {
- protected override initializeAsyncMacroCommand(): void {
- this.addSubCommand(() => new TestAsyncCommand1());
- this.addSubCommand(() => new TestAsyncCommand2());
- }
- execute(notification: INotification) {
- this.setOnComplete(() => {
- const vo = notification.body as AsyncCommandTestVO;
- vo.result = vo.result * vo.input
- })
- super.execute(notification);
- }
- }
+ test("testSetOnComplete", (done) => {
+ class TestAsyncCommand1 extends AsyncCommand {
+ override execute(note: INotification) {
+ setTimeout(() => {
+ const vo: AsyncCommandTestVO = note.body;
+ vo.result = vo.input * vo.input;
+ this.commandComplete();
+ }, 1000);
+ }
+ }
- const vo = new AsyncCommandTestVO(5);
- const asyncMacroCommand = new TestAsyncMacroCommand()
- const notification = new Notification("TestNotification", vo)
- asyncMacroCommand.execute(notification)
+ class TestAsyncCommand2 extends AsyncCommand {
+ override execute(note: INotification) {
setTimeout(() => {
- expect(vo.input).toEqual(5)
- expect(vo.result).toEqual(625)
- done()
- }, 3000);
+ const vo: AsyncCommandTestVO = note.body;
+ vo.result = vo.result * vo.input;
+ this.commandComplete();
+ }, 1000);
+ }
+ }
- });
+ class TestAsyncMacroCommand extends AsyncMacroCommand {
+ protected override initializeAsyncMacroCommand(): void {
+ this.addSubCommand(() => new TestAsyncCommand1());
+ this.addSubCommand(() => new TestAsyncCommand2());
+ }
+ execute(notification: INotification) {
+ this.setOnComplete(() => {
+ const vo = notification.body as AsyncCommandTestVO;
+ vo.result = vo.result * vo.input;
+ });
+ super.execute(notification);
+ }
+ }
+ const vo = new AsyncCommandTestVO(5);
+ const asyncMacroCommand = new TestAsyncMacroCommand();
+ const notification = new Notification("TestNotification", vo);
+ asyncMacroCommand.execute(notification);
+ setTimeout(() => {
+ expect(vo.input).toEqual(5);
+ expect(vo.result).toEqual(625);
+ done();
+ }, 3000);
+ });
});