diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-header-app.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-header-app.element.ts index 002c83520a..dae3d199c8 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-header-app.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-header-app.element.ts @@ -26,6 +26,7 @@ export class UmbCurrentUserHeaderApp extends UmbLitElement { constructor() { super(); this.consumeAllContexts(['umbCurrentUserStore', 'umbModalService'], (instances) => { + debugger; this._currentUserStore = instances['umbCurrentUserStore']; this._modalService = instances['umbModalService']; this._observeCurrentUser(); @@ -36,6 +37,7 @@ export class UmbCurrentUserHeaderApp extends UmbLitElement { if (!this._currentUserStore) return; this.observe(this._currentUserStore.currentUser, (currentUser) => { + debugger; this._currentUser = currentUser; }); } diff --git a/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-consumer.ts b/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-consumer.ts index e8c3cb8919..810c73d609 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-consumer.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-consumer.ts @@ -7,6 +7,12 @@ import { UmbContextRequestEventImplementation, UmbContextCallback } from './cont */ export class UmbContextConsumer { + + private _instance?: unknown; + get instance(): unknown | undefined { + return this._instance; + } + get consumerAlias() { return this._contextAlias; } @@ -20,11 +26,17 @@ export class UmbContextConsumer { */ constructor(protected target: EventTarget, private _contextAlias: string, private _callback: UmbContextCallback) {} + + private _onResponse = (instance: unknown) => { + this._instance = instance; + this._callback(instance); + } + /** * @memberof UmbContextConsumer */ public request() { - const event = new UmbContextRequestEventImplementation(this._contextAlias, this._callback); + const event = new UmbContextRequestEventImplementation(this._contextAlias, this._onResponse); this.target.dispatchEvent(event); } diff --git a/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-request.event.ts b/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-request.event.ts index ad1baad5c2..ad55c31881 100644 --- a/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-request.event.ts +++ b/src/Umbraco.Web.UI.Client/src/core/context-api/consume/context-request.event.ts @@ -1,6 +1,6 @@ export const umbContextRequestEventType = 'umb:context-request'; -export type UmbContextCallback = (instance: any) => void; +export type UmbContextCallback = (instance: unknown) => void; /** * @export diff --git a/src/Umbraco.Web.UI.Client/src/core/element/element.mixin.ts b/src/Umbraco.Web.UI.Client/src/core/element/element.mixin.ts index b61989baa4..03e964d8f6 100644 --- a/src/Umbraco.Web.UI.Client/src/core/element/element.mixin.ts +++ b/src/Umbraco.Web.UI.Client/src/core/element/element.mixin.ts @@ -66,10 +66,16 @@ export const UmbElementMixin = (superClass: T) new UmbContextConsumerController(this, alias, () => { resolvedAmount++; - //const allResolved = this.getControllers((ctrl: UmbControllerInterface):boolean => isContextConsumerType(ctrl) && _contextAliases.indexOf(ctrl.consumerAlias) !== -1 ); - + if (resolvedAmount === _contextAliases.length) { - callback(controllers); + + const result: ResolvedContexts = {}; + + controllers.forEach((contextCtrl: UmbContextConsumerController) => { + result[contextCtrl.consumerAlias] = contextCtrl.instance; + }); + + callback(result); } }) );