Last active
June 8, 2019 21:42
-
-
Save cevr/43f39c994d8e8f0a1548a90b9ec5ec3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { action } from "easy-peasy"; | |
let id = 0; | |
export default { | |
todos: {}, | |
// actions | |
add: action((state, text) => { | |
const todo = { | |
id: id++, | |
done: false, | |
text | |
}; | |
state.todos[todo.id] = todo; | |
}), | |
toggle: action((state, id) => { | |
state.todos[id] = { ...state.todos[id], done: !state.todos[id].done }; | |
}), | |
delete: action((state, id) => { | |
// 🤯 don't worry, we're using immer under the hood. | |
// All immutable pitchforks can be put down! | |
delete state.todos[id]; | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment