mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* change BaseRegistry to only have one type parameter Signed-off-by: Sebastian Malton <sebastian@malton.name>
28 lines
730 B
TypeScript
28 lines
730 B
TypeScript
// Base class for extensions-api registries
|
|
import { action, observable } from "mobx";
|
|
import { LensExtension } from "../lens-extension";
|
|
import { recitfy } from "../../common/utils";
|
|
|
|
export class BaseRegistry<T> {
|
|
private items = observable<T>([], { deep: false });
|
|
|
|
getItems(): T[] {
|
|
return this.items.toJS();
|
|
}
|
|
|
|
add(items: T | T[], ext?: LensExtension): () => void; // allow method overloading with required "ext"
|
|
@action
|
|
add(items: T | T[]) {
|
|
const itemArray = recitfy(items);
|
|
this.items.push(...itemArray);
|
|
return () => this.remove(...itemArray);
|
|
}
|
|
|
|
@action
|
|
remove(...items: T[]) {
|
|
items.forEach(item => {
|
|
this.items.remove(item); // works because of {deep: false};
|
|
});
|
|
}
|
|
}
|