"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const Async_1 = require("../../../../../types/interface/async/Async");
const _ids_1 = require("../../../../_ids");
class Listen extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['emitter', 'event'],
            fo: [],
            i: [],
            o: ['data'],
        }, {
            input: {
                emitter: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_LISTEN, 'remove');
        this._unlisten = undefined;
    }
    f({ emitter, event }) {
        emitter = (0, Async_1.Async)(emitter, ['EE'], this.__system.async);
        const listener = (data) => {
            this._output.data.push(data);
        };
        this._unlisten = emitter.$addListener({ event }, (args) => {
            const data = args[0];
            listener(data);
        });
    }
    d() {
        if (this._unlisten) {
            this._unlisten();
            this._unlisten = undefined;
            this._forward_empty('data');
        }
    }
}
exports.default = Listen;
//# sourceMappingURL=index.js.map