Skip to content

Instantly share code, notes, and snippets.

@bradfordlemley
Last active May 24, 2019 20:32
Show Gist options
  • Save bradfordlemley/3de75ed26d7781f8deaaa9da30448061 to your computer and use it in GitHub Desktop.
Save bradfordlemley/3de75ed26d7781f8deaaa9da30448061 to your computer and use it in GitHub Desktop.
Todo library using stated library base
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