"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Semifunctional_1 = require("../../../../../Class/Semifunctional");
const _ids_1 = require("../../../../_ids");
class Listen extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['emitter', 'event'],
            fo: [],
            i: ['remove'],
            o: ['data'],
        }, {
            input: {
                emitter: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_LISTEN);
        this._unlisten = undefined;
        this._remove = () => {
            this._unlisten();
            this._listener = undefined;
            this._unlisten = undefined;
        };
        this.addListener('destroy', () => {
            if (this._listener) {
                this._remove();
                this._forward_empty('data');
            }
        });
    }
    f({ emitter, event }) {
        const listener = (...data) => {
            if (this._paused) {
                return;
            }
            this._output.data.push(data[0]);
        };
        this._listener = listener;
        this._unlisten = emitter.addListener(event, this._listener);
    }
    d() {
        this._remove();
        this._forward_empty('data');
    }
    onIterDataInputData(name, data) {
        // if (name === 'remove') {
        if (this._listener) {
            this._remove();
            this._done();
        }
        // }
    }
}
exports.default = Listen;
//# sourceMappingURL=index.js.map