Last active
May 29, 2019 20:56
-
-
Save bradfordlemley/961ac5956b57843903d1dd4fb35295e1 to your computer and use it in GitHub Desktop.
Vanilla todo library with standardized state
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
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