"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReferenceCountedBase = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
/**
 * Base class to assist with implementing ReferenceCounted.
 */
class ReferenceCountedBase {
    constructor(refCount = 1) {
        this.refCount = refCount;
    }
    referenceAdded(count = 1) {
        this.refCount += count;
    }
    referenceRemoved(count = 1) {
        this.refCount -= count;
        (0, internal_1.assert)(this.refCount >= 0, 0x4c4 /* Negative ref count */);
        if (this.refCount === 0) {
            this.onUnreferenced();
        }
    }
    isShared() {
        return this.refCount > 1;
    }
    isUnreferenced() {
        return this.refCount === 0;
    }
}
exports.ReferenceCountedBase = ReferenceCountedBase;
//# sourceMappingURL=referenceCounting.js.map