构建 Logo 解释器及相关功能实现
1. 实现撤销和重做功能
1.1 配置存储
首先,我们需要配置存储,代码如下:
export const configureStore = (
storeEnhancers = [],
initialState = {}
) => {
return createStore(
combineReducers({
script: withUndoRedo(scriptReducer)
}),
initialState,
compose(...storeEnhancers)
);
};
1.2 添加撤销和重做按钮
为了使撤销和重做功能可访问,我们需要在菜单栏添加按钮,具体步骤如下:
1. 添加测试 :在 test/MenuButtons.test.js
文件底部,嵌套在 MenuButtons
的 describe
块内添加以下测试:
describe("undo button", () => {
it("renders", () => {
renderWithStore(<MenuButtons />);