Skip to content

Instantly share code, notes, and snippets.

@bradfordlemley
Last active May 29, 2019 20:56
Show Gist options
  • Save bradfordlemley/961ac5956b57843903d1dd4fb35295e1 to your computer and use it in GitHub Desktop.
Save bradfordlemley/961ac5956b57843903d1dd4fb35295e1 to your computer and use it in GitHub Desktop.
Vanilla todo library with standardized state
export default function createTodoLib() {
let state = {
todos: [],
isFetching: false,
};
return {
get state() {return state},
addTodo(title) {
state.todos = state.todos.concat({title});
},
async fetchTodos() {
state.isFetching = true;
const newTodos = await fetchFromCloud();
state.todos = state.todos.concat(newTodos);
state.isFetching = false;
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment