Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d622553
commit b29407b
Showing
5 changed files
with
148 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* A simple redux store/actions/reducer implementation. | ||
* A true app would be more complex and separated into different files. | ||
*/ | ||
import { configureStore, createSlice } from "@reduxjs/toolkit"; | ||
|
||
/* | ||
* The initial state of our store when the app loads. | ||
* Usually, you would fetch this from a server. | ||
*/ | ||
const defaultTasks = [ | ||
{ id: "1", title: "Something", state: "TASK_INBOX" }, | ||
{ id: "2", title: "Something more", state: "TASK_INBOX" }, | ||
{ id: "3", title: "Something else", state: "TASK_INBOX" }, | ||
{ id: "4", title: "Something again", state: "TASK_INBOX" }, | ||
]; | ||
|
||
/* | ||
* The store is created here. | ||
* You can read more about Redux Toolkit's slices in the docs: | ||
* https://redux-toolkit.js.org/api/createSlice | ||
*/ | ||
const TasksSlice = createSlice({ | ||
name: "tasks", | ||
initialState: defaultTasks, | ||
reducers: { | ||
updateTaskState: (state, action) => { | ||
const { id, newTaskState } = action.payload; | ||
const task = state.findIndex((task) => task.id === id); | ||
if (task >= 0) { | ||
state[task].state = newTaskState; | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
// The actions contained in the slice are exported for usage in our components | ||
export const { updateTaskState } = TasksSlice.actions; | ||
|
||
/* | ||
* Our app's store configuration goes here. | ||
* Read more about Redux's configureStore in the docs: | ||
* https://redux-toolkit.js.org/api/configureStore | ||
*/ | ||
const store = configureStore({ | ||
reducer: { | ||
tasks: TasksSlice.reducer, | ||
}, | ||
}); | ||
|
||
export default store; |
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