Skip to content
Snippets Groups Projects
Commit c060ba2a authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Port to EventBus

parent ce38bedf
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,7 @@ import {ScopedElementsMixin} from '@open-wc/scoped-elements'; ...@@ -5,8 +5,7 @@ import {ScopedElementsMixin} from '@open-wc/scoped-elements';
import JSONLD from 'vpu-common/jsonld'; import JSONLD from 'vpu-common/jsonld';
import * as commonUtils from 'vpu-common/utils'; import * as commonUtils from 'vpu-common/utils';
import * as commonStyles from 'vpu-common/styles'; import * as commonStyles from 'vpu-common/styles';
import * as events from 'vpu-common/events.js'; import {Icon, EventBus} from 'vpu-common';
import {Icon} from 'vpu-common';
import VPULitElement from 'vpu-common/vpu-lit-element'; import VPULitElement from 'vpu-common/vpu-lit-element';
import {KeycloakWrapper} from './keycloak.js'; import {KeycloakWrapper} from './keycloak.js';
...@@ -49,18 +48,7 @@ export class Auth extends ScopedElementsMixin(VPULitElement) { ...@@ -49,18 +48,7 @@ export class Auth extends ScopedElementsMixin(VPULitElement) {
this.person = null; this.person = null;
this.entryPointUrl = commonUtils.getAPiUrl(); this.entryPointUrl = commonUtils.getAPiUrl();
this.keycloakConfig = null; this.keycloakConfig = null;
const _getLoginData = () => {
const message = {
status: this._loginStatus,
token: this.token,
};
return message;
};
this._loginStatus = LoginStatus.UNKNOWN; this._loginStatus = LoginStatus.UNKNOWN;
this._emitter = new events.EventEmitter('vpu-auth-update', 'vpu-auth-update-request');
this._emitter.registerCallback(_getLoginData);
// Create the events // Create the events
this.initEvent = new CustomEvent("vpu-auth-init", { "detail": "KeyCloak init event", bubbles: true, composed: true }); this.initEvent = new CustomEvent("vpu-auth-init", { "detail": "KeyCloak init event", bubbles: true, composed: true });
...@@ -162,7 +150,13 @@ export class Auth extends ScopedElementsMixin(VPULitElement) { ...@@ -162,7 +150,13 @@ export class Auth extends ScopedElementsMixin(VPULitElement) {
return; return;
this._loginStatus = status; this._loginStatus = status;
this._emitter.emit();
this._bus.publish('auth-update', {
status: this._loginStatus,
token: this.token,
}, {
retain: true,
});
} }
/** /**
...@@ -197,6 +191,8 @@ export class Auth extends ScopedElementsMixin(VPULitElement) { ...@@ -197,6 +191,8 @@ export class Auth extends ScopedElementsMixin(VPULitElement) {
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
this._bus = new EventBus();
// Keycloak config // Keycloak config
let baseURL = ''; let baseURL = '';
let realm = ''; let realm = '';
...@@ -257,6 +253,7 @@ export class Auth extends ScopedElementsMixin(VPULitElement) { ...@@ -257,6 +253,7 @@ export class Auth extends ScopedElementsMixin(VPULitElement) {
} }
disconnectedCallback() { disconnectedCallback() {
this._bus.close();
this._kcwrapper.removeEventListener('changed', this._onKCChanged); this._kcwrapper.removeEventListener('changed', this._onKCChanged);
document.removeEventListener('click', this.closeDropdown); document.removeEventListener('click', this.closeDropdown);
super.disconnectedCallback(); super.disconnectedCallback();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment