last callback corrections

This commit is contained in:
Niels Lyngsø
2023-11-16 19:29:59 +01:00
parent abd7cab015
commit f0fbe18872
3 changed files with 22 additions and 8 deletions

View File

@@ -287,13 +287,15 @@ export abstract class UmbBaseExtensionInitializer<
}
public destroy(): void {
if (!this.#extensionRegistry) return;
this.#promiseResolvers = [];
this.#clearPermittedState();
this.#clearPermittedState(); // This fires the callback as not permitted, if it was permitted before.
this.#isPermitted = undefined;
this._isConditionsPositive = false;
this.#overwrites = [];
this.#cleanConditions();
//this.#onPermissionChanged = undefined;
this.#onPermissionChanged = undefined;
(this.#extensionRegistry as any) = undefined;
super.destroy();
// Destroy the conditions controllers, are begin destroyed cause they are controllers.
}

View File

@@ -120,11 +120,11 @@ 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);
done();
extensionController.destroy();
} else if (count === 3) {
done();
}
},
);
@@ -288,7 +288,12 @@ describe('UmbBaseExtensionsController', () => {
expect(permitted[0].alias).to.eq('Umb.Test.Extension.A');
extensionController.destroy();
} else if (count === 4) {
done();
// Expect that destroy will only result in one last callback with no permitted controllers.
expect(permitted.length).to.eq(0);
Promise.resolve().then(() => done()); // This wrap is to enable the test to detect if more callbacks are fired.
} else if (count === 5) {
// This should not happen, we do only want one last callback when destroyed.
expect(false).to.eq(true);
}
},
);

View File

@@ -151,10 +151,17 @@ export abstract class UmbBaseExtensionsInitializer<
}
public destroy() {
// The this.#extensionRegistry is an indication of wether this is already destroyed.
if (!this.#extensionRegistry) return;
const oldPermittedExtsLength = this._permittedExts.length;
this._extensions.length = 0;
this._permittedExts.length = 0;
if (oldPermittedExtsLength > 0) {
this.#onChange?.(this._permittedExts);
}
this.#onChange = undefined;
(this.#extensionRegistry as any) = undefined;
super.destroy();
this.#onChange?.(this._permittedExts);
//this.#onChange = undefined;
}
}