Skip to content

Instantly share code, notes, and snippets.

@vlas-ilya
Last active January 19, 2021 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlas-ilya/def2fa3ef6a2dec6b48418424486ad1c to your computer and use it in GitHub Desktop.
Save vlas-ilya/def2fa3ef6a2dec6b48418424486ad1c to your computer and use it in GitHub Desktop.
import { createStore, createEffect } from 'effector';
import { listApi } from '../../api/Todo';
const listStore = createStore([]);
const stateStore = createStore('INIT');
const loadTodoList = createEffect(() => listApi());
stateStore.on(loadTodoList, () => 'LOADING');
stateStore.on(loadTodoList.doneData, () => 'SUCCESS');
listStore.on(loadTodoList.doneData, (_, list) => list);
stateStore.on(loadTodoList.failData, () => 'ERROR');
listStore.on(loadTodoList.failData, () => []);
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