Path: blob/main/extensions/copilot/src/util/vs/base/common/observableInternal/set.ts
13406 views
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'12/*---------------------------------------------------------------------------------------------3* Copyright (c) Microsoft Corporation. All rights reserved.4* Licensed under the MIT License. See License.txt in the project root for license information.5*--------------------------------------------------------------------------------------------*/67import { IObservable, ITransaction } from '../observable';8import { observableValueOpts } from './observables/observableValueOpts';910export class ObservableSet<T> implements Set<T> {1112private readonly _data = new Set<T>();1314private _obs = observableValueOpts({ equalsFn: () => false }, this);1516readonly observable: IObservable<Set<T>> = this._obs;1718get size(): number {19return this._data.size;20}2122has(value: T): boolean {23return this._data.has(value);24}2526add(value: T, tx?: ITransaction): this {27const hadValue = this._data.has(value);28if (!hadValue) {29this._data.add(value);30this._obs.set(this, tx);31}32return this;33}3435delete(value: T, tx?: ITransaction): boolean {36const result = this._data.delete(value);37if (result) {38this._obs.set(this, tx);39}40return result;41}4243clear(tx?: ITransaction): void {44if (this._data.size > 0) {45this._data.clear();46this._obs.set(this, tx);47}48}4950forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void {51this._data.forEach((value, value2, _set) => {52// eslint-disable-next-line local/code-no-any-casts53callbackfn.call(thisArg, value, value2, this as any);54});55}5657*entries(): IterableIterator<[T, T]> {58for (const value of this._data) {59yield [value, value];60}61}6263*keys(): IterableIterator<T> {64yield* this._data.keys();65}6667*values(): IterableIterator<T> {68yield* this._data.values();69}7071[Symbol.iterator](): IterableIterator<T> {72return this.values();73}7475get [Symbol.toStringTag](): string {76return 'ObservableSet';77}78}798081