Skip to content

Commit

Permalink
Factors out updated handlers to functions and normalizes names of eve…
Browse files Browse the repository at this point in the history
…nt handlers (#3)
  • Loading branch information
olange committed Mar 6, 2019
1 parent 9df630e commit 645755f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/dia-show/dia-display-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class DiaDisplaySelector extends LitElement {
Array.from( this.displayList.values())
.map(( display) =>
html`<span id="${display}" class="item"
@click=${this.selected}>${display}</span>`)
@click=${this._onSelected}>${display}</span>`)
}</div>`;
}

Expand All @@ -41,7 +41,7 @@ export class DiaDisplaySelector extends LitElement {
this.displayList = new Set();
}

selected( e) {
_onSelected( e) {
const selectedDisplay = e.target.id;
this.dispatchEvent(
new CustomEvent( "display-selected", {
Expand Down
27 changes: 18 additions & 9 deletions packages/dia-show/dia-po.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,29 @@ export class DiaPo extends LitElement {

updated( changedProperties) {
console.log( `dia-po[${this.parentSlide}:${this.display}] › updated()`, changedProperties);
if( changedProperties.has( "activeSlide") || changedProperties.has( "activeDisplay")) {
this.hidden = ( typeof this.activeDisplay !== "undefined"
&& typeof this.display !== "undefined"
&& this.activeDisplay !== this.display)
||( typeof this.activeSlide !== "undefined"
&& typeof this.parentSlide !== "undefined"
&& this.activeSlide !== this.parentSlide);
if( changedProperties.has( "activeSlide")
|| changedProperties.has( "activeDisplay")) {
this._updatedActiveSlideOrDisplay();
}
if( changedProperties.has( "hidden")) {
this.querySelectorAll( "dia-livecode")
.forEach(( element) => element.hidden = this.hidden);
this._updatedHidden();
}
}

_updatedActiveSlideOrDisplay() {
this.hidden = (typeof this.activeDisplay !== "undefined"
&& typeof this.display !== "undefined"
&& this.activeDisplay !== this.display)
|| (typeof this.activeSlide !== "undefined"
&& typeof this.parentSlide !== "undefined"
&& this.activeSlide !== this.parentSlide);
}

_updatedHidden() {
this.querySelectorAll( "dia-livecode")
.forEach(( element) => element.hidden = this.hidden);
}

}

// Register the element with the browser
Expand Down
8 changes: 4 additions & 4 deletions packages/dia-show/dia-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ export class DiaShow extends LitElement {

updated( changedProperties) {
if( changedProperties.has( "slide")) {
this._switchActiveSlide();
this._updatedActiveSlide();
}
if( changedProperties.has( "display")) {
this._switchActiveDisplay();
this._updatedActiveDisplay();
}
}

// Propagate the active slide id to the ‹dia-slide› child elements,
// which will in turn hide/reveal themselves, and propagate the id
// to their child ‹dia-po› elements
_switchActiveSlide() {
_updatedActiveSlide() {
const activeSlideId = this.slide != null ? this.slide : undefined;
console.log( `dia-show › Switch to slide: ${activeSlideId}`);
this.querySelectorAll( "dia-slide")
Expand All @@ -62,7 +62,7 @@ export class DiaShow extends LitElement {
// Propagate the active display id to the ‹dia-slide› child elements,
// which will in turn propagate the id to their child ‹dia-po› elements,
// and the later will hide/reveal themselves
_switchActiveDisplay() {
_updatedActiveDisplay() {
const activeDisplayId = this.display != null ? this.display : undefined;
console.log( `dia-show › Switch to display: ${activeDisplayId}`);
this.querySelectorAll( "dia-slide")
Expand Down
29 changes: 21 additions & 8 deletions packages/dia-show/dia-slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,34 @@ export class DiaSlide extends LitElement {
updated( changedProperties) {
console.log( `dia-slide[${this.id}] › updated()`, changedProperties);
if( changedProperties.has( "activeSlide")) {
this.querySelectorAll( "dia-po")
.forEach(( element) => element.activeSlide = this.activeSlide);
this.hidden = (typeof this.activeSlide !== "undefined"
&& this.activeSlide !== this.id);
this._updatedActiveSlide();
}
if( changedProperties.has( "activeDisplay")) {
this.querySelectorAll( "dia-po")
.forEach(( element) => element.activeDisplay = this.activeDisplay);
this._updatedActiveDisplay();
}
if( changedProperties.has( "id")) {
this.querySelectorAll( "dia-po")
.forEach(( element) => element.parentSlide = this.id);
this._updatedId();
}
}

_updatedActiveSlide() {
this.querySelectorAll( "dia-po")
.forEach(( element) => element.activeSlide = this.activeSlide);

this.hidden = (typeof this.activeSlide !== "undefined"
&& this.activeSlide !== this.id);
}

_updatedActiveDisplay() {
this.querySelectorAll( "dia-po")
.forEach(( element) => element.activeDisplay = this.activeDisplay);
}

_updatedId() {
this.querySelectorAll( "dia-po")
.forEach(( element) => element.parentSlide = this.id);
}

}

// Register the element with the browser
Expand Down

0 comments on commit 645755f

Please sign in to comment.