"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Source = void 0;
class Source {
    constructor(data = null) {
        this._data = null;
        this._callback = [];
        this._data = data;
    }
    set(data) {
        this._data = data;
        for (const callback of this._callback) {
            callback(data);
        }
    }
    connect(callback) {
        this._callback.push(callback);
        if (this._data) {
            callback(this._data);
        }
        return () => {
            const i = this._callback.indexOf(callback);
            if (i > -1) {
                this._callback.splice(i, 1);
            }
            else {
                throw new Error('can only unlisten once');
            }
        };
    }
}
exports.Source = Source;
//# sourceMappingURL=Source.js.map