Skip to content

Commit

Permalink
Merges the {display,slide}-selected event listeners into one (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
olange committed Mar 6, 2019
1 parent b0faafd commit 3b29097
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions packages/dia-show/dia-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class DiaShow extends LitElement {
super();

// Attach event listeners
this.addEventListener( "display-selected", this._displaySelected);
this.addEventListener( "display-selected", this._onDisplaySelected);
this.addEventListener( "slide-selected", this._onSlideSelected);

// Public observed properties
this.slide = undefined;
Expand All @@ -39,24 +40,6 @@ export class DiaShow extends LitElement {
this._displayList = this._enumerateDisplays(); // returns a `Set`
}

firstUpdated() {
// Sets the new slide when the custom event `slide-selected` is fired from a child.
this.addEventListener("slide-selected", (e) => {
e.stopPropagation();
if(this.slide == undefined){
this.slide = e.detail.slide;
}
});

// Sets the new display when the custom event `display-selected` is fired from a child.
this.addEventListener("display-selected", (e) => {
e.stopPropagation();
if(this.display == undefined){
this.display = e.detail.display;
}
});
}

updated( changedProperties) {
if( changedProperties.has( "slide")) {
this._switchActiveSlide();
Expand Down Expand Up @@ -131,11 +114,20 @@ export class DiaShow extends LitElement {
return displays;
}

_displaySelected( e) {
e.stopPropagation();
// Sets the active display when the custom event `display-selected` is fired from a child.
_onDisplaySelected( e) {
const selectedDisplay = e.detail.display;
console.log( `dia-show › _displaySelected(): ${selectedDisplay}`);
console.log( `dia-show › on-display-selected: ${selectedDisplay}`);
this.display = selectedDisplay;
e.stopPropagation();
}

// Sets the active slide when the custom event `slide-selected` is fired from a child.
_onSlideSelected( e) {
const selectedSlide = e.detail.slide;
console.log( `dia-show › on-slide-selected: ${selectedSlide}`);
this.slide = selectedSlide;
e.stopPropagation();
}
}

Expand Down

0 comments on commit 3b29097

Please sign in to comment.