suggestions from jacob

This commit is contained in:
Niels Lyngsø
2023-08-04 09:29:14 +02:00
parent dcfd654c36
commit 9bb9e58eaa
4 changed files with 4 additions and 65 deletions

View File

@@ -107,7 +107,7 @@ export const UmbControllerHostBaseMixin = <T extends ClassConstructor<any>>(supe
destroy() {
this.#controllers.forEach((ctrl: UmbController) => ctrl.destroy());
this.#controllers = [];
this.#controllers.length = 0;
}
}

View File

@@ -57,7 +57,7 @@ export abstract class UmbBaseExtensionsController<
this._extensions.forEach((controller) => {
controller.destroy();
});
this._extensions = [];
this._extensions.length = 0;
// _permittedExts should have been cleared via the destroy callbacks.
return;
}
@@ -142,7 +142,7 @@ export abstract class UmbBaseExtensionsController<
public destroy() {
super.destroy();
this._extensions = [];
this._permittedExts = [];
this._extensions.length = 0;
this._permittedExts.length = 0;
}
}

View File

@@ -111,7 +111,6 @@ export class UmbExtensionRegistry<
}
register(manifest: ManifestTypes | ManifestKind<ManifestTypes>): void {
// TODO: Consider if we need to implement some safety features here, like checking if the object has a 'type' and/or 'alias'?
if (!manifest.type) {
console.error(`Extension is missing type`, manifest);
return;

View File

@@ -1,60 +0,0 @@
import { UmbBaseController, UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import {
ManifestCondition,
UmbConditionConfigBase,
UmbExtensionCondition,
} from '@umbraco-cms/backoffice/extension-api';
import { UMB_SECTION_CONTEXT_TOKEN } from '@umbraco-cms/backoffice/section';
export class UmbSectionAliasCondition extends UmbBaseController implements UmbExtensionCondition {
config: SectionAliasConditionConfig;
permitted = false;
#onChange: () => void;
constructor(args: { host: UmbControllerHost; config: SectionAliasConditionConfig; onChange: () => void }) {
super(args.host);
this.config = args.config;
this.#onChange = args.onChange;
this.consumeContext(UMB_SECTION_CONTEXT_TOKEN, (context) => {
//if (context) {
this.observe(
context.alias,
(sectionAlias) => {
// TODO: Would be nice to make the object fully controllable by each condition, but requires some typing system.
this.permitted = sectionAlias === this.config.match;
this.#onChange();
}
//,
//'_observeSectionAlias'
);
//}
// Niels: As is of this state, contexts cannot be unprovided, so this code is not needed:
/*else {
this.removeControllerByAlias('_observeSectionAlias');
if (this.permitted === true) {
this.permitted = false;
this.#onChange();
}
}*/
});
}
/*
hostDisconnected() {
super.hostDisconnected();
this.permitted = false;
this.#onChange();
}
*/
}
export const manifest: ManifestCondition = {
type: 'condition',
name: 'Section Alias Condition',
alias: 'Umb.Condition.SectionAlias',
class: UmbSectionAliasCondition,
};
export type SectionAliasConditionConfig = UmbConditionConfigBase & {
match: string;
};