Skip to content

Commit

Permalink
chore: Unify variables names with Set interface in ReactiveSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Exelord committed Sep 8, 2024
1 parent f6be2e0 commit 6fa04d7
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions packages/set/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ export class ReactiveSet<T> extends Set<T> {
if (values) for (const value of values) super.add(value);
}

// reads
[Symbol.iterator](): IterableIterator<T> {
return this.values();
}

get size(): number {
this.#triggers.track($KEYS);
return super.size;
}

has(v: T): boolean {
this.#triggers.track(v);
return super.has(v);
has(value: T): boolean {
this.#triggers.track(value);
return super.has(value);
}

keys(): IterableIterator<T> {
Expand All @@ -54,36 +57,36 @@ export class ReactiveSet<T> extends Set<T> {
}
}

[Symbol.iterator](): IterableIterator<T> {
return this.values();
}

forEach(callbackfn: (value1: T, value2: T, set: Set<T>) => void, thisArg?: any): void {
this.#triggers.track($KEYS);
super.forEach(callbackfn, thisArg);
}

// writes
add(v: T): this {
if (!super.has(v)) {
super.add(v);
add(value: T): this {
if (!super.has(value)) {
super.add(value);
batch(() => {
this.#triggers.dirty(v);
this.#triggers.dirty(value);
this.#triggers.dirty($KEYS);
});
}

return this;
}
delete(v: T): boolean {
const r = super.delete(v);
if (r) {

delete(value: T): boolean {
const result = super.delete(value);

if (result) {
batch(() => {
this.#triggers.dirty(v);
this.#triggers.dirty(value);
this.#triggers.dirty($KEYS);
});
}
return r;

return result;
}

clear(): void {
if (super.size) {
super.clear();
Expand Down Expand Up @@ -113,21 +116,25 @@ export class ReactiveWeakSet<T extends object> extends WeakSet<T> {
if (values) for (const value of values) super.add(value);
}

has(v: T): boolean {
this.#triggers.track(v);
return super.has(v);
has(value: T): boolean {
this.#triggers.track(value);
return super.has(value);
}
add(v: T): this {
if (!super.has(v)) {
super.add(v);
this.#triggers.dirty(v);

add(value: T): this {
if (!super.has(value)) {
super.add(value);
this.#triggers.dirty(value);
}
return this;
}
delete(v: T): boolean {
const deleted = super.delete(v);
deleted && this.#triggers.dirty(v);
return deleted;

delete(value: T): boolean {
const result = super.delete(value);

result && this.#triggers.dirty(value);

return result;
}
}

Expand Down

0 comments on commit 6fa04d7

Please sign in to comment.