Proff of concept for navigating to edit path when created

This commit is contained in:
Niels Lyngsø
2023-04-04 15:48:36 +02:00
parent 4a83bfa41d
commit 42f901aa41
11 changed files with 93 additions and 65 deletions

View File

@@ -5,6 +5,7 @@ export declare class UmbControllerHostElement extends HTMLElement {
hasController(controller: UmbControllerInterface): boolean;
getControllers(filterMethod: (ctrl: UmbControllerInterface) => boolean): UmbControllerInterface[];
addController(controller: UmbControllerInterface): void;
removeControllerByUnique(unique: UmbControllerInterface['unique']): void;
removeController(controller: UmbControllerInterface): void;
}
@@ -43,13 +44,7 @@ export const UmbControllerHostMixin = <T extends HTMLElementConstructor>(superCl
*/
addController(ctrl: UmbControllerInterface): void {
// Check if there is one already with same unique
if (ctrl.unique) {
this.#controllers.forEach((x) => {
if (x.unique === ctrl.unique) {
this.removeController(x);
}
});
}
this.removeControllerByUnique(ctrl.unique);
this.#controllers.push(ctrl);
if (this.#attached) {
@@ -57,6 +52,20 @@ export const UmbControllerHostMixin = <T extends HTMLElementConstructor>(superCl
}
}
/**
* Remove a controller from this element, by its unique/alias.
* @param {unknown} unique/alias
*/
removeControllerByUnique(unique: UmbControllerInterface['unique']): void {
if (unique) {
this.#controllers.forEach((x) => {
if (x.unique === unique) {
this.removeController(x);
}
});
}
}
/**
* Remove a controller from this element.
* Notice this will also destroy the controller.