Skip to content

Commit

Permalink
overload connect in mutationsandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagamihara Nadeshiko committed Sep 18, 2023
1 parent 1708cfe commit d4fb1b3
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/core/reactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,25 @@ export abstract class Reactor extends Component {
* @param src
* @param dst
*/

public connect<R, S extends R>(src: IOPort<S>, dst: IOPort<R>): void;
public connect<A extends T, R, T, S extends R>(
src: CallerPort<A, R>,
dst: CalleePort<T, S>
): void;
public connect<A extends T, R, T, S extends R>(
src: CallerPort<A, R> | IOPort<S>,
dst: CalleePort<T, S> | IOPort<R>
...[src, dst]:
| [IOPort<S>, IOPort<R>]
| [CallerPort<A, R>, CalleePort<T, S>]
): 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."
);
}
}

Expand Down Expand Up @@ -1840,10 +1849,13 @@ interface UtilityFunctions {
}

export interface MutationSandbox extends ReactionSandbox {
connect: <A extends T, R, T, S extends R>(
src: CallerPort<A, R> | IOPort<S>,
dst: CalleePort<T, S> | IOPort<R>
) => void;
connect: {
<R, S extends R>(src: IOPort<S>, dst: IOPort<R>): void;
<A extends T, R, T, S extends R>(
src: CallerPort<A, R>,
dst: CalleePort<T, S>
): void;
};

disconnect: <R, S extends R>(src: IOPort<S>, dst?: IOPort<R>) => void;

Expand Down

0 comments on commit d4fb1b3

Please sign in to comment.