From d4fb1b38eecdd30bcfa1294b9ee3bb00967b3fa8 Mon Sep 17 00:00:00 2001 From: Kagamihara Nadeshiko Date: Mon, 18 Sep 2023 14:06:58 -0700 Subject: [PATCH] overload connect in mutationsandbox --- src/core/reactor.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/core/reactor.ts b/src/core/reactor.ts index f0010c012..9b8b92c11 100644 --- a/src/core/reactor.ts +++ b/src/core/reactor.ts @@ -473,16 +473,25 @@ export abstract class Reactor extends Component { * @param src * @param dst */ + + public connect(src: IOPort, dst: IOPort): void; + public connect( + src: CallerPort, + dst: CalleePort + ): void; public connect( - src: CallerPort | IOPort, - dst: CalleePort | IOPort + ...[src, dst]: + | [IOPort, IOPort] + | [CallerPort, CalleePort] ): void { if (src instanceof CallerPort && dst instanceof CalleePort) { this.reactor._connectCall(src, dst); } else if (src instanceof IOPort && dst instanceof IOPort) { this.reactor._connect(src, dst); } else { - // ERROR + throw Error( + "Logically unreachable code: src and dst type mismatch, Caller(ee) port cannot be connected to IOPort." + ); } } @@ -1840,10 +1849,13 @@ interface UtilityFunctions { } export interface MutationSandbox extends ReactionSandbox { - connect: ( - src: CallerPort | IOPort, - dst: CalleePort | IOPort - ) => void; + connect: { + (src: IOPort, dst: IOPort): void; + ( + src: CallerPort, + dst: CalleePort + ): void; + }; disconnect: (src: IOPort, dst?: IOPort) => void;