Skip to content

Commit

Permalink
feat: 🎸 Deck extends an EventEmitter and produces exit event
Browse files Browse the repository at this point in the history
Deck extends from EventEmitter now and is able to emit event "exit" when
deck is got a request to exit. It is useful when you want to call some
routine after deck exits the presentation.
  • Loading branch information
ghaiklor committed May 8, 2020
1 parent 17be125 commit 2d28c52
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/kittik-deck/src/Deck.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Animationable } from 'kittik-animation-basic';
import { Canvas } from 'terminal-canvas';
import { DeckDeclaration } from './DeckDeclaration';
import { EventEmitter } from 'events';
import { ShapeRenderable } from 'kittik-shape-basic';
import { Slide } from 'kittik-slide';
import readline from 'readline';
Expand All @@ -12,13 +13,20 @@ export { DeckDeclaration } from './DeckDeclaration';
export { ShapeBuilder } from 'kittik-slide';
export { SlideBuilder } from 'kittik-slide';

export class Deck {
export declare interface Deck {
on: (event: 'exit', listener: () => void) => this
emit: (event: 'exit') => boolean
}

export class Deck extends EventEmitter {
public canvas: Canvas = Canvas.create();
private readonly slides: Slide[] = [];
private isRendering = false;
private currentSlideIndex = 0;

public constructor (declaration?: DeckDeclaration) {
super();

if (typeof declaration?.canvas !== 'undefined') {
this.canvas = declaration.canvas;
}
Expand Down Expand Up @@ -106,6 +114,8 @@ export class Deck {
public exit (): void {
process.stdin.pause();
process.stdin.removeAllListeners();

this.emit('exit');
}

private initSlides (declaration: DeckDeclaration): void {
Expand Down

0 comments on commit 2d28c52

Please sign in to comment.