-
Notifications
You must be signed in to change notification settings - Fork 0
/
todoActions.js
45 lines (40 loc) · 1.18 KB
/
todoActions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// @flow
type Action =
{ type: 'ADD_TODO', payload: string } |
{ type: 'REMOVE_TODO', payload: number } |
{ type : 'REMOVE_ALL_TODOS' };
type State = any;
type Dispatch = (action: Action | ThunkAction | PromiseAction) => any;
type GetState = () => State;
type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
type PromiseAction = Promise<Action>;
export function addTodo(todo: string): ThunkAction {
return function(dispatch: Dispatch) {
return dispatch({ // NOT ABLE TO PUT BREAKPOINT ON THIS LINE
type: 'ADD_TODO',
payload: todo
});
};
}
export function removeTodo(index: number): ThunkAction {
return function(dispatch: Dispatch) {
return dispatch({
type: 'REMOVE_TODO',
payload: index
});
};
}
export function clearAll(): ThunkAction {
return function(dispatch: Dispatch) {
return dispatch({
type: 'REMOVE_ALL_TODOS'
});
};
}
export function addRemoveClear(): ThunkAction {
return function(dispatch: Dispatch) {
dispatch(addTodo('something'));
dispatch(removeTodo(0));
dispatch(clearAll());
};
}