Skip to content

Commit 1738ed1

Browse files
committed
feat: 🎸 SlideBuilder can be started with predefined shapes\anim
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.
1 parent 1c7970e commit 1738ed1

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

packages/kittik-slide/spec/SlideBuilder.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,25 @@ describe('slide builder', () => {
6565
animations: ['Print']
6666
}]);
6767
});
68+
69+
it('should properly mix the predefined shapes and animations through start() method', () => {
70+
expect.hasAssertions();
71+
72+
const slide = SlideBuilder
73+
.start(
74+
{ 'Predefined Shape': ShapeBuilder.start('Text').end() },
75+
{ 'Predefined Animation': AnimationBuilder.start('Print').end() }
76+
)
77+
.withOrder('Predefined Shape', ['Predefined Animation'])
78+
.end();
79+
80+
expect(slide.shapes.size).toBe(1);
81+
expect(slide.shapes.get('Predefined Shape')).not.toBeUndefined();
82+
expect(slide.animations.size).toBe(1);
83+
expect(slide.animations.get('Predefined Animation')).not.toBeUndefined();
84+
expect(slide.order).toStrictEqual([{
85+
shape: 'Predefined Shape',
86+
animations: ['Predefined Animation']
87+
}]);
88+
});
6889
});

packages/kittik-slide/src/slide/SlideBuilder.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ type TAnimationAccumulator<TSlideBuilder, TNextAnimation> =
1616
export class SlideBuilder<TShape, TAnimation> {
1717
private readonly slide: Slide = new Slide();
1818

19-
public static start (): SlideBuilder<never, never> {
20-
return new this();
19+
public constructor (shapes: Record<string, ShapeRenderable> = {}, animations: Record<string, Animationable> = {}) {
20+
Object.keys(shapes).forEach((name) => this.slide.addShape(name, shapes[name]));
21+
Object.keys(animations).forEach((name) => this.slide.addAnimation(name, animations[name]));
22+
}
23+
24+
public static start <TShape extends string = never, TAnimation extends string = never>(
25+
shapes?: Record<TShape, ShapeRenderable>,
26+
animations?: Record<TAnimation, Animationable>
27+
): SlideBuilder<TShape, TAnimation> {
28+
return new this(shapes, animations);
2129
}
2230

2331
public withName (name: string): this {

0 commit comments

Comments
 (0)