Last active
May 24, 2019 20:32
-
-
Save bradfordlemley/3de75ed26d7781f8deaaa9da30448061 to your computer and use it in GitHub Desktop.
Todo library using stated library base
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
import createBase from './StatedLibBase'; | |
export default function createTodoLib() { | |
const base = createBase({ todos: [], isFetching: false }); | |
const {updateState, state$} = base; | |
return { | |
get state: {return base.state}, | |
state$, | |
addTodo(title) { | |
updateState({ todos: base.state.todos.concat({ title }) }); | |
}, | |
async fetchTodos() { | |
updateState({ isFetching: true }); | |
const newTodos = await fetchFromCloud(); | |
updateState({ | |
isFetching: false, | |
todos: base.state.todos.concat(newTodos), | |
}); | |
}, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment