Advertisement
cbigot

Untitled

Feb 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ...
  2. export const getAllTodos = () => {
  3.  
  4.     const todoList: Todo[] = [];
  5.  
  6.     return (dispatch: Function) => {
  7.         return getDB().then((db: PouchDB.Database) =>
  8.             // Demande des documents préfixés par 'todos'
  9.             db.allDocs({
  10.                 startkey: 'todo',
  11.                 endkey: 'todo\ufff0',
  12.                 descending: false,
  13.                 include_docs: true
  14.             })
  15.             .then(data => {
  16.                 // Récupération des todos renvoyés par Pouch
  17.                 data.rows.map((item) => todoList.push(item.doc as Todo));
  18.  
  19.                 // Envoie de la liste des todos au store
  20.                 dispatch({
  21.                     type: Action.GET_ALL_TODOS,
  22.                     todoList: fromJS(todoList)
  23.                 });
  24.             })
  25.         );
  26.     };
  27. };
  28. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement