"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Primitive_1 = require("../../../../Primitive");
const _ids_1 = require("../../../_ids");
class Spark extends Primitive_1.Primitive {
    constructor(system) {
        super({
            i: ['a'],
            o: ['a'],
        }, {}, system, _ids_1.ID_SPARK);
        this._ran = false;
        this._loop = (data) => {
            if (this._ran) {
                return;
            }
            this._ran = true;
            this._output.a.push(data);
        };
        this.addListener('reset', () => {
            this._ran = false;
            const a = this._input.a.peak();
            if (a !== undefined) {
                this._loop(a);
            }
        });
    }
    onDataInputDrop(name, data) {
        this._ran = false;
        if (this._output.a.active()) {
            this._forward_empty('a');
        }
    }
    onDataInputData(name, data) {
        this._loop(data);
    }
    snapshotSelf() {
        return {
            ...super.snapshotSelf(),
            _ran: this._ran,
        };
    }
    restoreSelf(state) {
        const { _ran, ...rest } = state;
        super.restoreSelf(rest);
        this._ran = _ran;
    }
}
exports.default = Spark;
//# sourceMappingURL=index.js.map