From fdca4170881679608f530b64b10f85b43614cd9b Mon Sep 17 00:00:00 2001 From: Eugen Neuber <eugen.neuber@tugraz.at> Date: Wed, 13 Jan 2021 11:28:34 +0100 Subject: [PATCH] Add "root" attribute for catch-all providers "root" provider handle all events (and cancel propagation) --- packages/provider/src/dbp-provider-demo.js | 3 ++- packages/provider/src/provider.js | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/provider/src/dbp-provider-demo.js b/packages/provider/src/dbp-provider-demo.js index 9db89214..da88f580 100644 --- a/packages/provider/src/dbp-provider-demo.js +++ b/packages/provider/src/dbp-provider-demo.js @@ -52,13 +52,14 @@ class ProviderDemo extends ScopedElementsMixin(LitElement) { render() { return html` <dbp-provider id="root" + root="1" blah="777" availability="global" lang="de" ><section class="section"> <p>Provider <em>"root"</em> is the top most in hierarchy:</p> <pre> -<dbp-provider id="root" availability="global" ></dbp-provider> +<dbp-provider id="root" root="1" availability="global" ></dbp-provider> </pre> <div class="container"> <h1 class="title">Provider-Demo</h1> diff --git a/packages/provider/src/provider.js b/packages/provider/src/provider.js index d8d0f932..7df12452 100644 --- a/packages/provider/src/provider.js +++ b/packages/provider/src/provider.js @@ -2,6 +2,7 @@ export class Provider extends HTMLElement { constructor() { super(); this.callbackStore = []; + this.root = false; console.log('Provider constructor()'); } @@ -11,7 +12,7 @@ export class Provider extends HTMLElement { const that = this; 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.dir(e.detail); e.detail.callback(that[e.detail.name]); @@ -21,7 +22,7 @@ export class Provider extends HTMLElement { this.addEventListener('subscribe', function (e) { const name = e.detail.name; - if (that[name]) { + if (that[name] || that.root) { console.log('Provider(' + that.id() + ') eventListener("subscribe",..) name "' + name + '" found.'); that.callbackStore.push({name: name, callback: e.detail.callback, sender: e.detail.sender}); @@ -33,7 +34,7 @@ export class Provider extends HTMLElement { this.addEventListener('unsubscribe', function (e) { const name = e.detail.name; const sender = e.detail.sender; - if (that[name]) { + if (that[name] || that.root) { console.log('Provider(' + that.id() + ') eventListener("unsubscribe",..) name "' + name + '" found.'); that.callbackStore.forEach(item => { if (item.sender === sender && item.name === name) { @@ -52,7 +53,7 @@ export class Provider extends HTMLElement { const name = e.detail.name; const value = e.detail.value; - if (that[name]) { + if (that[name] || that.root) { console.log('Provider(' + that.id() + ') eventListener("set-property",..) name "' + name + '" found.'); that[name] = value; -- GitLab