refactor method

This commit is contained in:
Niels Lyngsø
2023-01-02 20:56:47 +01:00
parent 0c7275230a
commit 6377220cdd

View File

@@ -62,26 +62,19 @@ export const UmbElementMixin = <T extends HTMLElementConstructor>(superClass: T)
* @memberof UmbElementMixin
*/
consumeAllContexts(_contextAliases: Array<string>, callback: (_instances: ResolvedContexts) => void) {
this._createContextConsumers(_contextAliases, (resolvedContexts) => {
callback?.(resolvedContexts);
});
}
private _createContextConsumers(aliases: Array<string>, resolvedCallback: (_instances: ResolvedContexts) => void) {
aliases.forEach((alias) =>
_contextAliases.forEach((alias) =>
new UmbContextConsumerController(this, alias, () => {
const allResolved = this.getControllers((ctrl: UmbControllerInterface):boolean => isContextConsumerType(ctrl) && aliases.indexOf(ctrl.consumerAlias) !== -1 );
const allResolved = this.getControllers((ctrl: UmbControllerInterface):boolean => isContextConsumerType(ctrl) && _contextAliases.indexOf(ctrl.consumerAlias) !== -1 );
if (allResolved.length === aliases.length) {
resolvedCallback(allResolved);
if (allResolved.length === _contextAliases.length) {
callback(allResolved);
}
})
);
}
}
return UmbElementMixinClass as unknown as HTMLElementConstructor<UmbElementMixinInterface> & T;