|
@@ -34,14 +34,23 @@ export const Component = def(class Component extends HTMLElement {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- constructor (property_values) {
|
|
|
|
- super();
|
|
|
|
-
|
|
|
|
|
|
+ _set_dom_based_on_render_mode () {
|
|
if ( this.constructor.RENDER_MODE === Component.NO_SHADOW ) {
|
|
if ( this.constructor.RENDER_MODE === Component.NO_SHADOW ) {
|
|
this.dom_ = this;
|
|
this.dom_ = this;
|
|
} else {
|
|
} else {
|
|
this.dom_ = this.attachShadow({ mode: 'open' });
|
|
this.dom_ = this.attachShadow({ mode: 'open' });
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ constructor (property_values) {
|
|
|
|
+ super();
|
|
|
|
+
|
|
|
|
+ property_values = property_values || {};
|
|
|
|
+
|
|
|
|
+ // We allow a subclass of component to define custom behavior
|
|
|
|
+ // for the `RENDER_MODE` static property. This is so JustHTML
|
|
|
|
+ // can have ths `no_shadow: true` option.
|
|
|
|
+ this._set_dom_based_on_render_mode({ property_values });
|
|
|
|
|
|
this.values_ = {};
|
|
this.values_ = {};
|
|
|
|
|
|
@@ -104,6 +113,10 @@ export const Component = def(class Component extends HTMLElement {
|
|
}
|
|
}
|
|
|
|
|
|
get (key) {
|
|
get (key) {
|
|
|
|
+ if ( ! this.values_.hasOwnProperty(key) ) {
|
|
|
|
+ throw new Error(`Unknown property \`${key}\` in ${
|
|
|
|
+ this.constructor.ID || this.constructor.name}`);
|
|
|
|
+ }
|
|
return this.values_[key].get();
|
|
return this.values_[key].get();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -130,6 +143,11 @@ export const Component = def(class Component extends HTMLElement {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if ( destination instanceof ShadowRoot ) {
|
|
|
|
+ destination.appendChild(this);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
if ( destination.$ === 'placeholder' ) {
|
|
if ( destination.$ === 'placeholder' ) {
|
|
destination.replaceWith(this);
|
|
destination.replaceWith(this);
|
|
return;
|
|
return;
|
|
@@ -162,6 +180,14 @@ export const Component = def(class Component extends HTMLElement {
|
|
get_api_ () {
|
|
get_api_ () {
|
|
return {
|
|
return {
|
|
listen: (name, callback) => {
|
|
listen: (name, callback) => {
|
|
|
|
+ if ( Array.isArray(name) ) {
|
|
|
|
+ const names = name;
|
|
|
|
+ for ( const name of names ) {
|
|
|
|
+ this.values_[name].sub((_, more) => {
|
|
|
|
+ callback(this, { ...more, name });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
this.values_[name].sub(callback);
|
|
this.values_[name].sub(callback);
|
|
callback(this.values_[name].get(), {});
|
|
callback(this.values_[name].get(), {});
|
|
}
|
|
}
|