mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
21 lines
512 B
TypeScript
21 lines
512 B
TypeScript
import { action, ObservableSet } from "mobx";
|
|
|
|
export class ToggleSet<T> extends Set<T> {
|
|
public toggle(value: T): void {
|
|
if (!this.delete(value)) {
|
|
// Set.prototype.delete returns false if `value` was not in the set
|
|
this.add(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class ObservableToggleSet<T> extends ObservableSet<T> {
|
|
@action
|
|
public toggle(value: T): void {
|
|
if (!this.delete(value)) {
|
|
// Set.prototype.delete returns false if `value` was not in the set
|
|
this.add(value);
|
|
}
|
|
}
|
|
}
|