Skip to content
Snippets Groups Projects
Commit fdca4170 authored by Neuber, Eugen Ramon's avatar Neuber, Eugen Ramon :speech_balloon:
Browse files

Add "root" attribute for catch-all providers

"root" provider handle all events (and cancel propagation)
parent cbd8fe28
No related branches found
No related tags found
1 merge request!28Observer test
Pipeline #15679 passed
...@@ -52,13 +52,14 @@ class ProviderDemo extends ScopedElementsMixin(LitElement) { ...@@ -52,13 +52,14 @@ class ProviderDemo extends ScopedElementsMixin(LitElement) {
render() { render() {
return html` return html`
<dbp-provider id="root" <dbp-provider id="root"
root="1"
blah="777" blah="777"
availability="global" availability="global"
lang="de" lang="de"
><section class="section"> ><section class="section">
<p>Provider <em>"root"</em> is the top most in hierarchy:</p> <p>Provider <em>"root"</em> is the top most in hierarchy:</p>
<pre> <pre>
&lt;dbp-provider id="root" availability="global" >&lt;/dbp-provider&gt; &lt;dbp-provider id="root" root="1" availability="global" >&lt;/dbp-provider&gt;
</pre> </pre>
<div class="container"> <div class="container">
<h1 class="title">Provider-Demo</h1> <h1 class="title">Provider-Demo</h1>
......
...@@ -2,6 +2,7 @@ export class Provider extends HTMLElement { ...@@ -2,6 +2,7 @@ export class Provider extends HTMLElement {
constructor() { constructor() {
super(); super();
this.callbackStore = []; this.callbackStore = [];
this.root = false;
console.log('Provider constructor()'); console.log('Provider constructor()');
} }
...@@ -11,7 +12,7 @@ export class Provider extends HTMLElement { ...@@ -11,7 +12,7 @@ export class Provider extends HTMLElement {
const that = this; const that = this;
this.addEventListener('inherit', function (e) { this.addEventListener('inherit', function (e) {
if (that[e.detail.name]) { if (that[e.detail.name] || that.root) {
console.log('Provider(' + that.id() + ') eventListener("inherit",..) name "' + e.detail.name + '" found.'); console.log('Provider(' + that.id() + ') eventListener("inherit",..) name "' + e.detail.name + '" found.');
//console.dir(e.detail); //console.dir(e.detail);
e.detail.callback(that[e.detail.name]); e.detail.callback(that[e.detail.name]);
...@@ -21,7 +22,7 @@ export class Provider extends HTMLElement { ...@@ -21,7 +22,7 @@ export class Provider extends HTMLElement {
this.addEventListener('subscribe', function (e) { this.addEventListener('subscribe', function (e) {
const name = e.detail.name; const name = e.detail.name;
if (that[name]) { if (that[name] || that.root) {
console.log('Provider(' + that.id() + ') eventListener("subscribe",..) name "' + name + '" found.'); console.log('Provider(' + that.id() + ') eventListener("subscribe",..) name "' + name + '" found.');
that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender}); that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender});
...@@ -33,7 +34,7 @@ export class Provider extends HTMLElement { ...@@ -33,7 +34,7 @@ export class Provider extends HTMLElement {
this.addEventListener('unsubscribe', function (e) { this.addEventListener('unsubscribe', function (e) {
const name = e.detail.name; const name = e.detail.name;
const sender = e.detail.sender; const sender = e.detail.sender;
if (that[name]) { if (that[name] || that.root) {
console.log('Provider(' + that.id() + ') eventListener("unsubscribe",..) name "' + name + '" found.'); console.log('Provider(' + that.id() + ') eventListener("unsubscribe",..) name "' + name + '" found.');
that.callbackStore.forEach(item => { that.callbackStore.forEach(item => {
if (item.sender === sender && item.name === name) { if (item.sender === sender && item.name === name) {
...@@ -52,7 +53,7 @@ export class Provider extends HTMLElement { ...@@ -52,7 +53,7 @@ export class Provider extends HTMLElement {
const name = e.detail.name; const name = e.detail.name;
const value = e.detail.value; const value = e.detail.value;
if (that[name]) { if (that[name] || that.root) {
console.log('Provider(' + that.id() + ') eventListener("set-property",..) name "' + name + '" found.'); console.log('Provider(' + that.id() + ') eventListener("set-property",..) name "' + name + '" found.');
that[name] = value; that[name] = value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment