Skip to content

Instantly share code, notes, and snippets.

@cevr
Last active June 8, 2019 21:42
Show Gist options
  • Save cevr/43f39c994d8e8f0a1548a90b9ec5ec3e to your computer and use it in GitHub Desktop.
Save cevr/43f39c994d8e8f0a1548a90b9ec5ec3e to your computer and use it in GitHub Desktop.
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