destroy only leaves by one final callback

This commit is contained in:
Niels Lyngsø
2023-11-16 18:57:38 +01:00
parent b495e38017
commit abd7cab015
2 changed files with 7 additions and 24 deletions

View File

@@ -149,28 +149,16 @@ describe('UmbBaseExtensionsController', () => {
if (count === 1) {
// First callback gives just one. We need to make a feature to gather changes to only reply after a computation cycle if we like to avoid this.
expect(permitted.length).to.eq(1);
}
if (count === 2) {
} else if (count === 2) {
expect(permitted.length).to.eq(2);
}
if (count === 3) {
} else if (count === 3) {
expect(permitted.length).to.eq(3);
expect(permitted[0].alias).to.eq('Umb.Test.Extension.A');
expect(permitted[1].alias).to.eq('Umb.Test.Extension.B');
expect(permitted[2].alias).to.eq('Umb.Test.Extension.Extra');
extensionController.destroy();
}
// TODO: Make sure we dont get several callbacks.
if (count === 4) {
// Cause we destroyed there will be a last call to reset permitted controllers:
expect(permitted.length).to.eq(2);
}
if (count === 5) {
// Cause we destroyed there will be a last call to reset permitted controllers:
expect(permitted.length).to.eq(1);
}
if (count === 6) {
} else if (count === 4) {
// Cause we destroyed there will be a last call to reset permitted controllers:
expect(permitted.length).to.eq(0);
done();
@@ -218,8 +206,7 @@ describe('UmbBaseExtensionsController', () => {
// First callback gives just one. We need to make a feature to gather changes to only reply after a computation cycle if we like to avoid this.
expect(permitted.length).to.eq(1);
expect(permitted[0].alias).to.eq('Umb.Test.Extension.A');
}
if (count === 2) {
} else if (count === 2) {
// Still just equal one, as the second one overwrites the first one.
expect(permitted.length).to.eq(1);
expect(permitted[0].alias).to.eq('Umb.Test.Extension.B');
@@ -289,8 +276,7 @@ describe('UmbBaseExtensionsController', () => {
// First callback gives just one. We need to make a feature to gather changes to only reply after a computation cycle if we like to avoid this.
expect(permitted.length).to.eq(1);
expect(permitted[0].alias).to.eq('Umb.Test.Extension.A');
}
if (count === 2) {
} else if (count === 2) {
// Still just equal one, as the second one overwrites the first one.
expect(permitted.length).to.eq(1);
expect(permitted[0].alias).to.eq('Umb.Test.Extension.B');

View File

@@ -6,7 +6,6 @@ import type {
UmbExtensionRegistry,
} from '@umbraco-cms/backoffice/extension-api';
import { UmbBaseController, type UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbObserverController } from '@umbraco-cms/backoffice/observable-api';
export type PermittedControllerType<ControllerType extends { manifest: any }> = ControllerType & {
manifest: Required<Pick<ControllerType, 'manifest'>>;
@@ -29,8 +28,6 @@ export abstract class UmbBaseExtensionsInitializer<
protected _extensions: Array<ControllerType> = [];
private _permittedExts: Array<MyPermittedControllerType> = [];
#observerCtrlTest?: UmbObserverController;
asPromise(): Promise<void> {
return new Promise((resolve) => {
this._permittedExts.length > 0 ? resolve() : this.#promiseResolvers.push(resolve);
@@ -57,7 +54,7 @@ export abstract class UmbBaseExtensionsInitializer<
if (this.#filter) {
source = source.pipe(map((extensions: Array<ManifestType>) => extensions.filter(this.#filter!)));
}
this.#observerCtrlTest = this.observe(source, this.#gotManifests, '_observeManifests') as any;
this.observe(source, this.#gotManifests, '_observeManifests') as any;
}
#gotManifests = (manifests: Array<ManifestType>) => {
@@ -154,9 +151,9 @@ export abstract class UmbBaseExtensionsInitializer<
}
public destroy() {
super.destroy();
this._extensions.length = 0;
this._permittedExts.length = 0;
super.destroy();
this.#onChange?.(this._permittedExts);
//this.#onChange = undefined;
}