From 55b18f2c86cd53d97d53e5bfdd90073887d4ffe8 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio@bekerle.com>
Date: Thu, 4 Feb 2021 08:44:10 +0100
Subject: [PATCH] Prefix provider events

---
 packages/auth/README.md                      |  2 +-
 packages/auth/src/auth-keycloak.js           |  2 +-
 packages/provider/src/adapter-lit-element.js | 14 +++++++-------
 packages/provider/src/provider.js            | 12 ++++++------
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/packages/auth/README.md b/packages/auth/README.md
index 91839c7c..9b1a061b 100644
--- a/packages/auth/README.md
+++ b/packages/auth/README.md
@@ -38,7 +38,7 @@ npm i @dbp-toolkit/auth
 
 ### Emitted attribute
 
-The component emits a `set-property` event for the attribute `auth`:
+The component emits a `dbp-set-property` event for the attribute `auth`:
 
 - `auth.subject`: Keycloak username
 - `auth.token`: Keycloak token to send with your requests
diff --git a/packages/auth/src/auth-keycloak.js b/packages/auth/src/auth-keycloak.js
index fd4ddfea..f72d7dd3 100644
--- a/packages/auth/src/auth-keycloak.js
+++ b/packages/auth/src/auth-keycloak.js
@@ -10,7 +10,7 @@ import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element";
  * Keycloak auth web component
  * https://www.keycloak.org/docs/latest/securing_apps/index.html#_javascript_adapter
  *
- * Emits a set-property event for the attribute "auth":
+ * Emits a dbp-set-property event for the attribute "auth":
  *   auth.subject: Keycloak username
  *   auth.token: Keycloak token to send with your requests
  *   auth.user-full-name: Full name of the user
diff --git a/packages/provider/src/adapter-lit-element.js b/packages/provider/src/adapter-lit-element.js
index 3635d6e5..fc61bdbe 100644
--- a/packages/provider/src/adapter-lit-element.js
+++ b/packages/provider/src/adapter-lit-element.js
@@ -80,10 +80,10 @@ export class AdapterLitElement extends LitElement {
 
         const that = this;
 
-        this.addEventListener('subscribe', function (e) {
+        this.addEventListener('dbp-subscribe', function (e) {
             const name = e.detail.name;
             if (that.hasProperty(name) || that.root) {
-                console.log('AdapterLitElementProvider(' + that.tagName + ') eventListener("subscribe",..) name "' + name + '" found.');
+                console.log('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-subscribe",..) name "' + name + '" found.');
                 that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender});
 
                 e.detail.callback(that.getProperty(name));
@@ -91,11 +91,11 @@ export class AdapterLitElement extends LitElement {
             }
         }, false);
 
-        this.addEventListener('unsubscribe', function (e) {
+        this.addEventListener('dbp-unsubscribe', function (e) {
             const name = e.detail.name;
             const sender = e.detail.sender;
             if (that.hasProperty(name) || that.root) {
-                console.log('AdapterLitElementProvider(' + that.tagName + ') eventListener("unsubscribe",..) name "' + name + '" found.');
+                console.log('AdapterLitElementProvider(' + that.tagName + ') eventListener("dbp-unsubscribe",..) name "' + name + '" found.');
                 that.callbackStore.forEach(item => {
                     if (item.sender === sender && item.name === name) {
                         const index = that.callbackStore.indexOf(item);
@@ -185,7 +185,7 @@ export class AdapterLitElement extends LitElement {
         const local = pair[0];
         const global = pair[1] || local;
         const that = this;
-        const event = new CustomEvent('subscribe',
+        const event = new CustomEvent('dbp-subscribe',
             {
                 bubbles: true,
                 composed: true,
@@ -224,7 +224,7 @@ export class AdapterLitElement extends LitElement {
         console.log('AdapterLitElement(' + this.tagName + ') unSubscribeProviderFor( ' + element + ' )');
         const pair = element.trim().split(':');
         const global = pair[1] || pair[0];
-        const event = new CustomEvent('unsubscribe',
+        const event = new CustomEvent('dbp-unsubscribe',
             {
                 bubbles: true,
                 composed: true,
@@ -302,7 +302,7 @@ export class AdapterLitElement extends LitElement {
      * @returns {boolean}
      */
     sendSetPropertyEvent(name, value) {
-        const event = new CustomEvent("set-property", {
+        const event = new CustomEvent('dbp-set-property', {
             bubbles: true,
             composed: true,
             detail: {'name': name, 'value': value}
diff --git a/packages/provider/src/provider.js b/packages/provider/src/provider.js
index fc3aff38..26e885f2 100644
--- a/packages/provider/src/provider.js
+++ b/packages/provider/src/provider.js
@@ -37,10 +37,10 @@ export class Provider extends HTMLElement {
 
         const that = this;
 
-        this.addEventListener('subscribe', function (e) {
+        this.addEventListener('dbp-subscribe', function (e) {
             const name = e.detail.name;
             if (that.hasProperty(name) || that.root) {
-                console.log('Provider(' + that.id + ') eventListener("subscribe",..) name "' + name + '" found.');
+                console.log('Provider(' + that.id + ') eventListener("dbp-subscribe",..) name "' + name + '" found.');
                 that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender});
 
                 e.detail.callback(that.getProperty(name));
@@ -48,11 +48,11 @@ export class Provider extends HTMLElement {
             }
         }, false);
 
-        this.addEventListener('unsubscribe', function (e) {
+        this.addEventListener('dbp-unsubscribe', function (e) {
             const name = e.detail.name;
             const sender = e.detail.sender;
             if (that.hasProperty(name) || that.root) {
-                console.log('Provider(' + that.id + ') eventListener("unsubscribe",..) name "' + name + '" found.');
+                console.log('Provider(' + that.id + ') eventListener("dbp-unsubscribe",..) name "' + name + '" found.');
                 that.callbackStore.forEach(item => {
                     if (item.sender === sender && item.name === name) {
                         const index = that.callbackStore.indexOf(item);
@@ -66,12 +66,12 @@ export class Provider extends HTMLElement {
         }, false);
 
         // listen to property changes
-        this.addEventListener('set-property', function (e) {
+        this.addEventListener('dbp-set-property', function (e) {
             const name = e.detail.name;
             const value = e.detail.value;
 
             if (that.hasProperty(name) || that.root) {
-                console.log('Provider(' + that.id + ') eventListener("set-property",..) name "' + name + '" found.');
+                console.log('Provider(' + that.id + ') eventListener("dbp-set-property",..) name "' + name + '" found.');
                 that.setProperty(name, value);
 
                 that.callbackStore.forEach(item => {
-- 
GitLab