Skip to content

Commit f11ab5d

Browse files
committed
fix: add initialize action to properly set totalSteps
1 parent 2026e99 commit f11ab5d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/state/animationSlice.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const UPDATE_FORMULA = 'animation/updateFormula';
4747
export const SET_ALGORITHM = 'animation/setAlgorithm';
4848
export const SET_CURRENT_STEP = 'animation/setCurrentStep';
4949
export const SET_PLAYBACK_SPEED = 'animation/setPlaybackSpeed';
50+
export const INITIALIZE = 'animation/initialize';
5051

5152
// 动作创建器
5253
export const playPause = () => ({ type: PLAY_PAUSE });
@@ -104,6 +105,16 @@ export function animationReducer(state = initialState, action: any): AnimationSt
104105
return { ...state, currentStep: newStep };
105106
case SET_PLAYBACK_SPEED:
106107
return { ...state, playbackSpeed: Math.max(0.1, action.payload) };
108+
case INITIALIZE:
109+
return {
110+
...state,
111+
timeline: action.payload.timeline || [],
112+
totalSteps: action.payload.timeline ? action.payload.timeline.length : 0,
113+
staircase: action.payload.staircase || { nodes: [], links: [] },
114+
matrix: action.payload.matrix || [],
115+
formula: action.payload.formula || '',
116+
currentStep: 0
117+
};
107118
default:
108119
return state;
109120
}

0 commit comments

Comments
 (0)