Skip to content

Commit

Permalink
fix: added states to merge method
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelOsborne committed Aug 2, 2023
1 parent 7aaebb2 commit f3c4238
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
17 changes: 5 additions & 12 deletions apps/node/lf-interactivity-page-generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ async function createDotLottie() {
url: 'https://assets2.lottiefiles.com/packages/lf20_4fET62.json',
})
.addState({
id: 'state_segments',
state: {
descriptor: {
id: 'state_segments',
initial: 'loopState',
},
states: {
animationId: 'segments',
loopState: {
animationId: 'segments',
statePlaybackSettings: {
autoplay: true,
loop: true,
Expand All @@ -57,15 +56,14 @@ async function createDotLottie() {
url: 'https://assets9.lottiefiles.com/packages/lf20_gr2cHM.json',
})
.addState({
id: 'state_segments_on_hover',
state: {
descriptor: {
id: 'state_segments_on_hover',
initial: 'loopState',
},
states: {
animationId: 'segments_on_hover',
loopState: {
animationId: 'segments_on_hover',
statePlaybackSettings: {
autoplay: true,
loop: true,
Expand All @@ -81,7 +79,6 @@ async function createDotLottie() {
url: 'https://assets8.lottiefiles.com/packages/lf20_zwath9pn.json',
})
.addState({
id: 'state_animation_on_hover',
state: {
descriptor: {
id: 'state_animation_on_hover',
Expand All @@ -104,14 +101,14 @@ async function createDotLottie() {
url: 'https://assets8.lottiefiles.com/private_files/lf30_tnblylie.json',
})
.addState({
id: 'state_toggle',
state: {
descriptor: {
id: 'state_toggle',
initial: 'startIdle',
},
states: {
startIdle: {
animationId: 'toggle',
statePlaybackSettings: {
autoplay: false,
loop: false,
Expand Down Expand Up @@ -157,7 +154,6 @@ async function createDotLottie() {
url: 'https://assets4.lottiefiles.com/packages/lf20_zyquagfl.json',
})
.addState({
id: 'exploding_pigeon',
state: {
descriptor: {
id: 'exploding_pigeon',
Expand Down Expand Up @@ -205,14 +201,13 @@ async function createDotLottie() {
})
.addAnimation({
id: 'repeat',
url: 'https://assets4.lottiefiles.com/packages/lf20_bshezgfo.json',
url: 'https://lottie.host/82f9aac1-c166-4124-9143-002bf32e235f/p1fb9yQ3lu.json',
})
.addAnimation({
id: 'repeat_second_animation',
url: 'https://assets2.lottiefiles.com/packages/lf20_2m1smtya.json',
url: 'https://lottie.host/5f095db6-2486-4020-ba31-77ef9697d031/izCcpDAsdG.json',
})
.addState({
id: 'state_repeat',
state: {
descriptor: {
id: 'state_repeat',
Expand All @@ -225,7 +220,6 @@ async function createDotLottie() {
autoplay: true,
loop: 3,
direction: 1,
segments: 'repeat',
},
onComplete: {
state: 'success',
Expand Down Expand Up @@ -258,7 +252,6 @@ async function createDotLottie() {
url: 'https://assets9.lottiefiles.com/packages/lf20_pKiaUR.json',
})
.addState({
id: 'state_load_in_queue_1',
state: {
descriptor: {
id: 'state_load_in_queue_1',
Expand Down
9 changes: 9 additions & 0 deletions packages/dotlottie-js/src/common/dotlottie-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,15 @@ export class DotLottieCommon {
});
});
});

dotlottie.states.forEach((state) => {
const stateOption = {
state: state.state,
zipOptions: state.zipOptions,
};

mergedDotlottie.addState(stateOption);
});
}

return mergedDotlottie;
Expand Down
6 changes: 3 additions & 3 deletions packages/dotlottie-js/src/common/dotlottie-state-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class DotLottieStateCommon {

protected _zipOptions: ZipOptions;

protected _state?: DotLottieState | undefined;
protected _state: DotLottieState;

public constructor(options: StateOptions) {
this._requireValidId(options.state.descriptor.id);
Expand Down Expand Up @@ -47,11 +47,11 @@ export class DotLottieStateCommon {
this._id = id;
}

public get state(): DotLottieState | undefined {
public get state(): DotLottieState {
return this._state;
}

public set state(state: DotLottieState | undefined) {
public set state(state: DotLottieState) {
this._state = state;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/dotlottie-js/src/tests/lottie-state-browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ describe('LottieState', () => {

it('gets and sets the data', async () => {
// arrange
const state = new LottieState({ state: PigeonState });
const pigeonState = new LottieState({ state: PigeonState });

// assert
expect(state.id).toEqual(PigeonState.descriptor.id);
expect(pigeonState.id).toEqual(PigeonState.descriptor.id);

expect(state.state?.descriptor.initial).toEqual(PigeonState.descriptor.initial);
expect(pigeonState.state.descriptor.initial).toEqual(PigeonState.descriptor.initial);

expect(state.state?.states).toEqual(PigeonState.states);
expect(pigeonState.state.states).toEqual(PigeonState.states);

const dotlottie = new DotLottie();

Expand Down
8 changes: 4 additions & 4 deletions packages/dotlottie-js/src/tests/lottie-state-node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ describe('LottieState', () => {

it('gets and sets the data', async () => {
// arrange
const state = new LottieState({ state: PigeonState });
const pigeonState = new LottieState({ state: PigeonState });

// assert
expect(state.id).toEqual(PigeonState.descriptor.id);
expect(pigeonState.id).toEqual(PigeonState.descriptor.id);

expect(state.state?.descriptor.initial).toEqual(PigeonState.descriptor.initial);
expect(pigeonState.state.descriptor.initial).toEqual(PigeonState.descriptor.initial);

expect(state.state?.states).toEqual(PigeonState.states);
expect(pigeonState.state.states).toEqual(PigeonState.states);

const dotlottie = new DotLottie();

Expand Down

0 comments on commit f3c4238

Please sign in to comment.