Skip to content

Commit

Permalink
feat: 🎸 SlideBuilder can be started with predefined shapes\anim
Browse files Browse the repository at this point in the history
SlideBuilder.start() method accepts now two arguments: a Record with
shape names as keys and ShapeRenderable as values and a Record with
animation names as keys and Animationable as values. These are mixing
into slide instance when instantiating a builder instance. Also, it
improves type information and allows to make a predefined set of
shapes\animations that can be shared amongst different SlideBuilders.
  • Loading branch information
ghaiklor committed May 9, 2020
1 parent 1c7970e commit 1738ed1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/kittik-slide/spec/SlideBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,25 @@ describe('slide builder', () => {
animations: ['Print']
}]);
});

it('should properly mix the predefined shapes and animations through start() method', () => {
expect.hasAssertions();

const slide = SlideBuilder
.start(
{ 'Predefined Shape': ShapeBuilder.start('Text').end() },
{ 'Predefined Animation': AnimationBuilder.start('Print').end() }
)
.withOrder('Predefined Shape', ['Predefined Animation'])
.end();

expect(slide.shapes.size).toBe(1);
expect(slide.shapes.get('Predefined Shape')).not.toBeUndefined();
expect(slide.animations.size).toBe(1);
expect(slide.animations.get('Predefined Animation')).not.toBeUndefined();
expect(slide.order).toStrictEqual([{
shape: 'Predefined Shape',
animations: ['Predefined Animation']
}]);
});
});
12 changes: 10 additions & 2 deletions packages/kittik-slide/src/slide/SlideBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ type TAnimationAccumulator<TSlideBuilder, TNextAnimation> =
export class SlideBuilder<TShape, TAnimation> {
private readonly slide: Slide = new Slide();

public static start (): SlideBuilder<never, never> {
return new this();
public constructor (shapes: Record<string, ShapeRenderable> = {}, animations: Record<string, Animationable> = {}) {
Object.keys(shapes).forEach((name) => this.slide.addShape(name, shapes[name]));
Object.keys(animations).forEach((name) => this.slide.addAnimation(name, animations[name]));
}

public static start <TShape extends string = never, TAnimation extends string = never>(
shapes?: Record<TShape, ShapeRenderable>,
animations?: Record<TAnimation, Animationable>
): SlideBuilder<TShape, TAnimation> {
return new this(shapes, animations);
}

public withName (name: string): this {
Expand Down

0 comments on commit 1738ed1

Please sign in to comment.