Last active
January 19, 2021 05:47
-
-
Save vlas-ilya/a92c1c802bf3711e3531eddbea0f79d1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { createStore, createEffect } from 'effector'; | |
import { listApi } from '../../api/Todo'; | |
const store = createStore({ | |
list: [], | |
state: 'INIT' | |
}); | |
const loadTodoList = createEffect(listApi); | |
store.on(loadTodoList, (store) => ({ | |
...store, | |
state: 'LOADING' | |
})); | |
store.on(loadTodoList.doneData, (_, list) => ({ | |
list, | |
state: 'SUCCESS' | |
})); | |
store.on(loadTodoList.failData, () => ({ | |
list: [], | |
state: 'ERROR' | |
})); | |
const listStore = store.map(store => store.list); | |
const stateStore = store.map(store => store.state); | |
const pageMounted = loadTodoList.prepend(() => null); | |
export { | |
listStore, | |
stateStore, | |
pageMounted | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment