"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleObservingDependent = void 0;
const core_utils_1 = require("@fluidframework/core-utils");
/**
 * A basic {@link ObservingDependent} implementation.
 */
class SimpleObservingDependent {
    constructor(markInvalid, computationName = "SimpleObservingDependent") {
        this.markInvalid = markInvalid;
        this.computationName = computationName;
        this._dependees = [];
    }
    listDependees() {
        return this._dependees;
    }
    registerDependee(dependee) {
        this._dependees.push(dependee);
    }
    /**
     * Unregister from dependees as a dependent. Necessary as part of disposal and markInvalid.
     */
    unregisterDependees() {
        (0, core_utils_1.assert)(this._dependees !== null, 0x309 /* Cannot unregister dependees on a disposed SimpleObservingDependent. */);
        for (const dependee of this._dependees) {
            // remove references to this from each dependee
            dependee.removeDependent(this);
        }
        // remove references of each dependee
        this._dependees.length = 0;
    }
    /**
     * Disconnect from all other proxies and clear. This object is not usable after dispose.
     */
    dispose() {
        // Null out fields to make this object error if used after disposed
        this.unregisterDependees();
        this._dependees = null;
    }
}
exports.SimpleObservingDependent = SimpleObservingDependent;
//# sourceMappingURL=simpleObservingDependent.js.map