import {my} from "my-ts"; import * as rx from "rxjs"; import { IObserverWithSubscription } from "../../common/common.interfaces"; import { IInputChannel } from "../hillock/hillock.interface"; import { IOutputChannel } from "../terminal/terminal.interface"; import {IOneWaySynapse} from "./one-way-synapse.interface"; export class OneWaySynapse implements IOneWaySynapse { public get isDisconnected(): boolean { return this.hillock.isDisconnected; } public get hasConnections(): boolean { return this.terminal.hasConnections; } private hillock: IInputChannel; private terminal: IOutputChannel; /** * */ constructor(hillock: IInputChannel, terminal: IOutputChannel) { this.hillock = hillock; this.terminal = terminal; } public connectTo(source: rx.Observable): IOneWaySynapse { this.hillock.connectTo(source); this.tryConnectHillockWithTerminal(); return this; } public observeWith(observer: IObserverWithSubscription): IOneWaySynapse { this.terminal.observeWith(observer); this.tryConnectHillockWithTerminal(); return this; } private tryConnectHillockWithTerminal(): void { if (this.terminal.hasConnections === false) { return; } this.hillock.observeWith({ id: "o1", observer : { // tslint:disable-next-line:no-empty complete: () => { } , // tslint:disable-next-line:no-empty error: (err) => { } , next: (x) => { this.terminal.transmit(x); }, }, subscription: null, }); } }