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