change BaseRegistry to only have one type parameter (#1474)

* change BaseRegistry to only have one type parameter

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2020-11-23 12:54:39 -05:00
1 parent 0a5e7a048d
commit 5005d34c2e
5 files changed
+23 -10

No files matched your search

+7 -6
View File
@@ -1,20 +1,21 @@
// 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 = object, I extends T = T> {
export class BaseRegistry<T> {
private items = observable<T>([], { deep: false });
getItems(): I[] {
return this.items.toJS() as I[];
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 normalizedItems = (Array.isArray(items) ? items : [items]);
this.items.push(...normalizedItems);
return () => this.remove(...normalizedItems);
const itemArray = recitfy(items);
this.items.push(...itemArray);
return () => this.remove(...itemArray);
}
@action
+5 -3
View File
@@ -7,6 +7,7 @@ import { compile } from "path-to-regexp";
import { BaseRegistry } from "./base-registry";
import { LensExtension } from "../lens-extension";
import logger from "../../main/logger";
import { recitfy } from "../../common/utils";
export interface PageRegistration {
/**
@@ -59,12 +60,13 @@ export function getExtensionPageUrl<P extends object>({ extensionId, pageId = ""
return extPageRoutePath;
}
export class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
export class PageRegistry extends BaseRegistry<RegisteredPage> {
@action
add(items: PageRegistration[], ext: LensExtension) {
add(items: PageRegistration | PageRegistration[], ext: LensExtension) {
const itemArray = recitfy(items);
let registeredPages: RegisteredPage[] = [];
try {
registeredPages = items.map(page => ({
registeredPages = itemArray.map(page => ({
...page,
extensionId: ext.name,
routePath: getExtensionPageUrl({ extensionId: ext.name, pageId: page.id ?? page.routePath }),