-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: record application state in undo/redo history
- Loading branch information
Showing
9 changed files
with
130 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { SetStateAction, createReducer } from "../../reducer"; | ||
import { AppData, AppState, Config, Data } from "../../types/Config"; | ||
|
||
type Props = { | ||
Comp: { | ||
prop: string; | ||
}; | ||
}; | ||
const defaultData: Data = { root: { title: "" }, content: [], zones: {} }; | ||
|
||
const defaultState: AppState = { leftSideBarVisible: true }; | ||
|
||
describe("State reducer", () => { | ||
const config: Config<Props> = { | ||
components: { | ||
Comp: { | ||
defaultProps: { prop: "example" }, | ||
render: () => <div />, | ||
}, | ||
}, | ||
}; | ||
|
||
const reducer = createReducer({ config }); | ||
|
||
describe("setState action", () => { | ||
it("should insert data into the state", () => { | ||
const state: AppData = { state: defaultState, data: defaultData }; | ||
|
||
const action: SetStateAction = { | ||
type: "setState", | ||
state: { leftSideBarVisible: false }, | ||
}; | ||
|
||
const newState = reducer(state, action); | ||
expect(newState.state.leftSideBarVisible).toEqual(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AppState } from "../types/Config"; | ||
import { PuckAction } from "./actions"; | ||
|
||
export const reduceState = (state: AppState, action: PuckAction) => { | ||
if (action.type === "setState") { | ||
return { | ||
...state, | ||
...action.state, | ||
}; | ||
} | ||
|
||
return state; | ||
}; |
Oops, something went wrong.