mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Get rid of this.disposers while registering stuff in extensions (#1148)
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
b765ee11bb
commit
67754ffbb9
15 files changed
+141
-197
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { readJsonSync } from "fs-extra";
|
||||
import { action, observable, toJS } from "mobx";
|
||||
import logger from "../main/logger";
|
||||
import { BaseRegistry } from "./registries/base-registry";
|
||||
|
||||
export type ExtensionId = string | ExtensionPackageJsonPath;
|
||||
export type ExtensionPackageJsonPath = string;
|
||||
@@ -25,7 +26,7 @@ export interface ExtensionManifest extends ExtensionModel {
|
||||
export class LensExtension implements ExtensionModel {
|
||||
public id: ExtensionId;
|
||||
public updateUrl: string;
|
||||
protected disposers: Function[] = [];
|
||||
protected disposers: (() => void)[] = [];
|
||||
|
||||
@observable name = "";
|
||||
@observable description = "";
|
||||
@@ -77,6 +78,14 @@ export class LensExtension implements ExtensionModel {
|
||||
// mock
|
||||
}
|
||||
|
||||
registerTo<T = any>(registry: BaseRegistry<T>, items: T[] = []) {
|
||||
const disposers = items.map(item => registry.add(item));
|
||||
this.disposers.push(...disposers);
|
||||
return () => {
|
||||
this.disposers = this.disposers.filter(disposer => !disposers.includes(disposer))
|
||||
};
|
||||
}
|
||||
|
||||
getMeta() {
|
||||
return toJS({
|
||||
id: this.id,
|
||||
|
||||
Reference in new issue
Block a user