Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
feat(#20): when deck and slides are loaded, emit an event
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Dec 4, 2018
1 parent 6e39736 commit 4f9a912
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/features/extra.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ await deck.print();

| Event | Emitted value | Description |
| -------------------------- |:-----------------:|:-----------------:|
| slidesDidLoad | string[] | Emitted when the deck and all slides have loaded. Emit the an ordered list of all the tag names of the slides. |
| slideNextDidChange | number | Emitted when the next slide has started. Emit the index of the new active slide. |
| slidePrevDidChange | number | Emitted when the previous slide has ended. Emit the index of the new active slide. |
| slideToChange | number | Emitted when a specific slide as selected. Emit the index of the new selected slide. |
Expand Down
1 change: 1 addition & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export namespace Components {
'onSlidePrevDidChange'?: (event: CustomEvent<number>) => void;
'onSlideToChange'?: (event: CustomEvent<number>) => void;
'onSlideWillChange'?: (event: CustomEvent<number>) => void;
'onSlidesDidLoad'?: (event: CustomEvent<string[]>) => void;
'pager'?: boolean;
'pagerPercentage'?: boolean;
}
Expand Down
19 changes: 18 additions & 1 deletion src/components/deck/deckdeckgo-deck/deckdeckgo-deck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class DeckdeckgoDeck {
@State()
private length: number = 0;

@Event() slidesDidLoad: EventEmitter<string[]>;
@Event() slideNextDidChange: EventEmitter<number>;
@Event() slidePrevDidChange: EventEmitter<number>;
@Event() slideToChange: EventEmitter<number>;
Expand Down Expand Up @@ -245,8 +246,24 @@ export class DeckdeckgoDeck {
/* BEGIN: Slide length and active index */

@Listen('slideDidLoad')
slideDidLoad() {
async slideDidLoad() {
this.length++;

await this.emitSlidesDidLoad();
}

private emitSlidesDidLoad(): Promise<void> {
return new Promise<void>((resolve) => {
const definedSlides: HTMLCollection = this.el.children;
const loadedSlides: NodeListOf<HTMLElement> = this.el.querySelectorAll('.deckgo-slide-container');

if (definedSlides && loadedSlides && loadedSlides.length === definedSlides.length && definedSlides.length === this.length) {
const orderedSlidesTagNames: string[] = Array.from(loadedSlides).map((slide: HTMLElement) => { return slide.tagName});
this.slidesDidLoad.emit(orderedSlidesTagNames);
}

resolve();
});
}

@Method()
Expand Down

0 comments on commit 4f9a912

Please sign in to comment.