Skip to content

Commit

Permalink
refactor: 💡 add re-exports for Slide types to outer packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaiklor committed Mar 18, 2020
1 parent ff5b44d commit 7644ad2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/kittik-slide/src/animation/Animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Focus } from 'kittik-animation-focus';
import { Print } from 'kittik-animation-print';
import { Slide } from 'kittik-animation-slide';

export const ANIMATIONS = new Map<string, { fromObject<T extends AnimationObject>(obj: T): Animationable }>([
export type AnimationType = 'Focus' | 'Print' | 'Slide';

export const ANIMATIONS = new Map<AnimationType, { fromObject<T extends AnimationObject>(obj: T): Animationable }>([
['Focus', Focus],
['Print', Print],
['Slide', Slide]
Expand Down
4 changes: 3 additions & 1 deletion src/kittik-slide/src/shape/Shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { Rectangle } from 'kittik-shape-rectangle';
import { ShapeRenderable, ShapeObject } from 'kittik-shape-basic';
import { Text } from 'kittik-shape-text';

export const SHAPES = new Map<string, { fromObject<T extends ShapeObject>(obj: T, cursor: Canvas): ShapeRenderable }>([
export type ShapeType = 'Code' | 'FigText' | 'Image' | 'Rectangle' | 'Text';

export const SHAPES = new Map<ShapeType, { fromObject<T extends ShapeObject>(obj: T, cursor: Canvas): ShapeRenderable }>([
['Code', Code],
['FigText', FigText],
['Image', Image],
Expand Down
15 changes: 11 additions & 4 deletions src/kittik-slide/src/slide/Slide.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Animationable } from 'kittik-animation-basic';
import { AnimationDeclaration } from '../animation/AnimationDeclaration';
import { ANIMATIONS } from '../animation/Animations';
import { ANIMATIONS, AnimationType } from '../animation/Animations';
import { Canvas } from 'terminal-canvas';
import { OrderDeclaration } from './OrderDeclaration';
import { ShapeDeclaration } from '../shape/ShapeDeclaration';
import { ShapeRenderable } from 'kittik-shape-basic';
import { SHAPES } from '../shape/Shapes';
import { SHAPES, ShapeType } from '../shape/Shapes';
import { SlideDeclaration } from './SlideDeclaration';

export { AnimationDeclaration } from '../animation/AnimationDeclaration';
export { AnimationType } from '../animation/Animations';
export { OrderDeclaration } from './OrderDeclaration';
export { ShapeDeclaration } from '../shape/ShapeDeclaration';
export { ShapeType } from '../shape/Shapes';
export { SlideDeclaration } from './SlideDeclaration';

export class Slide {
private readonly cursor: Canvas;
private readonly shapes: Map<string, ShapeRenderable>;
Expand All @@ -25,7 +32,7 @@ export class Slide {
const map = new Map<string, ShapeRenderable>();

declaration.forEach(shapeDeclaration => {
const ctor = SHAPES.get(shapeDeclaration.type);
const ctor = SHAPES.get(shapeDeclaration.type as ShapeType);

if (ctor === undefined) {
throw new Error(`Shape "${shapeDeclaration.name}" (${shapeDeclaration.type}) is unknown for me, maybe you made a typo?`);
Expand All @@ -41,7 +48,7 @@ export class Slide {
const map = new Map<string, Animationable>();

declaration.forEach(animationDeclaration => {
const ctor = ANIMATIONS.get(animationDeclaration.type);
const ctor = ANIMATIONS.get(animationDeclaration.type as AnimationType);

if (ctor === undefined) {
throw new Error(`Animation "${animationDeclaration.name}" (${animationDeclaration.type}) is unknown for me, maybe you made a typo?`);
Expand Down

0 comments on commit 7644ad2

Please sign in to comment.