more destroying

This commit is contained in:
Niels Lyngsø
2024-02-22 13:27:13 +01:00
parent 9e4f9505c3
commit 6bf42d5a44
7 changed files with 21 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import type { UmbContextToken } from '../context-api/index.js';
import type { UmbControllerHost } from '../controller-api/index.js';
import type { UmbContext } from './context.interface.js';
import { UmbBaseController } from './controller-base.class.js';
/**
@@ -7,10 +8,12 @@ import { UmbBaseController } from './controller-base.class.js';
*
*/
export abstract class UmbContextBase<
ContextType,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
GivenContextToken extends UmbContextToken<any, ContextType> = UmbContextToken<any, ContextType>,
> extends UmbBaseController {
ContextType,
GivenContextToken extends UmbContextToken<ContextType, ContextType> = UmbContextToken<ContextType, ContextType>,
>
extends UmbBaseController
implements UmbContext
{
constructor(host: UmbControllerHost, contextToken: GivenContextToken | string) {
super(host, contextToken.toString());
this.provideContext(contextToken, this as unknown as ContextType);

View File

@@ -0,0 +1,3 @@
import type { UmbController } from '../controller-api/controller.interface.js';
export interface UmbContext extends UmbController {}

View File

@@ -1,4 +1,5 @@
export * from './class.interface.js';
export * from './class.mixin.js';
export * from './context.interface.js';
export * from './context-base.class.js';
export * from './controller-base.class.js';

View File

@@ -65,6 +65,7 @@ export class UmbLocalizationController<LocalizationSetType extends UmbLocalizati
destroy(): void {
this.#host?.removeController(this);
this.#hostEl = undefined as any;
this.#usedKeys.length = 0;
}
documentUpdate() {

View File

@@ -170,6 +170,10 @@ export class UmbModalRouteRegistrationController<D extends object = object, R =
}
public destroy(): void {
this.hostDisconnected();
this.#host?.removeController(this);
this.#host = undefined as any;
this.#modalRegistration = undefined;
this.#uniquePaths = undefined as any;
this.#routeContext = undefined;
}
}

View File

@@ -1,4 +1,5 @@
import type { UmbVariantId } from '../../variant/variant-id.class.js';
import type { UmbContext } from '@umbraco-cms/backoffice/class-api';
import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
/**
@@ -15,7 +16,7 @@ import type { Observable } from '@umbraco-cms/backoffice/external/rxjs';
* Others might have saved publishing status.
* Also setting the name is an additional feature.
*/
export interface UmbPropertyDatasetContext {
export interface UmbPropertyDatasetContext extends UmbContext {
getEntityType(): string;
getUnique(): string | undefined;
getVariantId: () => UmbVariantId;
@@ -26,8 +27,6 @@ export interface UmbPropertyDatasetContext {
// Should it be possible to get the properties as a list of property aliases?
//readonly properties: Observable<Array<string>>;
destroy(): void;
// Property methods:
propertyVariantId?: (propertyAlias: string) => Promise<Observable<UmbVariantId | undefined>>;
propertyValueByAlias<ReturnType = unknown>(propertyAlias: string): Promise<Observable<ReturnType | undefined>>;

View File

@@ -148,6 +148,7 @@ export class UmbPropertyContext<ValueType = any> extends UmbBaseController {
}
public destroy(): void {
super.destroy();
this.#alias.destroy();
this.#label.destroy();
this.#description.destroy();
@@ -155,6 +156,7 @@ export class UmbPropertyContext<ValueType = any> extends UmbBaseController {
this.#value.destroy();
this.#configCollection.destroy();
this._providerController.destroy(); // This would also be handled by the controller host, but if someone wanted to replace/remove this context without the host being destroyed. Then we have clean up out selfs here.
this.#datasetContext = undefined;
}
}