Guest User

Untitled

a guest
Feb 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. const useNormalizedApi = () => {
  2. let db = useDB();
  3.  
  4. return {
  5. ...
  6. deleteTodo: async (id) => {
  7. let todo = await api.deleteTodo(id);
  8. let { result, entities } = normalize(
  9. todo,
  10. apiSchemas.deleteTodoResponseSchema
  11. );
  12. db.mergeEntities({
  13. Todo: {
  14. [id]: {
  15. isDeleted: true
  16. }
  17. }
  18. });
  19. db.updateStoredQuery(
  20. 'ALL_TODOS',
  21. (prevArray) => prevArray.filter(todoId => todoId != id)
  22. );
  23. },
  24. ...
  25. };
  26. };
  27.  
  28. const TodosComponent = (props) => {
  29. let db = useDB();
  30.  
  31. let allTodosQuery = db.getStoredQuery('ALL_TODOS');
  32. let todos = db.executeQuery(allTodosQuery);
  33.  
  34. return (
  35. <JSON data={todos} />
  36. )
  37. }
Add Comment
Please, Sign In to add comment