fix consumeAllContexts
This commit is contained in:
@@ -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<UserDetails>(this._currentUserStore.currentUser, (currentUser) => {
|
||||
debugger;
|
||||
this._currentUser = currentUser;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const umbContextRequestEventType = 'umb:context-request';
|
||||
|
||||
export type UmbContextCallback = (instance: any) => void;
|
||||
export type UmbContextCallback = (instance: unknown) => void;
|
||||
|
||||
/**
|
||||
* @export
|
||||
|
||||
@@ -66,10 +66,16 @@ export const UmbElementMixin = <T extends HTMLElementConstructor>(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);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user