You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
804 B

// @flow
import type { counterStateType } from '../reducers/counter';
type actionType = {
+type: string
};
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER';
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER';
export function increment() {
return {
type: INCREMENT_COUNTER
};
}
export function decrement() {
return {
type: DECREMENT_COUNTER
};
}
export function incrementIfOdd() {
return (dispatch: (action: actionType) => void, getState: () => counterStateType) => {
const { counter } = getState();
if (counter % 2 === 0) {
return;
}
dispatch(increment());
};
}
export function incrementAsync(delay: number = 1000) {
return (dispatch: (action: actionType) => void) => {
setTimeout(() => {
dispatch(increment());
}, delay);
};
}