step 9 exercise complete!

This commit is contained in:
Ken
2019-02-20 11:01:57 -08:00
parent 716644aec7
commit dd45492657
27 changed files with 523 additions and 3 deletions

View File

@@ -0,0 +1,51 @@
import uuid from 'uuid/v4';
import { Store } from '../store';
import * as service from '../service';
export const actions = {
addTodo: (label: string) => ({ type: 'addTodo', id: uuid(), label }),
remove: (id: string) => ({ type: 'remove', id }),
complete: (id: string) => ({ type: 'complete', id }),
clear: () => ({ type: 'clear' }),
setFilter: (filter: string) => ({ type: 'setFilter', filter })
};
export const actionsWithService = {
addTodo: (label: string) => {
return async (dispatch: any, getState: () => Store) => {
// Replace the return true with:
// 1. first call the actions.addTodo() function
// 2. store the resultant id
// 3. dispatch the action message generated by that call
// 4. pass the id and the todo from the state into the service call service.add()
return true;
};
},
remove: (id: string) => {
return async (dispatch: any, getState: () => Store) => {
// Replace the return true with:
// 1. dispatch a remove action with the id
// 2. await on the call to the service.remove()
return true;
};
},
complete: (id: string) => {
// ** Now it's your turn to write the thunk! **
// Replace the return Promise.resolve(true) with:
// 1. return an async function with the arguments of dispatch and getState
// 2. dispatch a remove action with the id
// 3. await on the call to the service.update()
return Promise.resolve(true);
},
clear: () => {
// ** Write your own thunk again! **
// Replace the return Promise.resolve(true) with:
// 1. return an async function with the arguments of dispatch and getState
// 2. dispatch a clear action
// 3. await on the call to the service.updateAll()
return Promise.resolve(true);
}
};