Slide 17
Slide 17 text
Definition of Action Creator
// @flow
import Dispatcher from './Dispatcher';
type CREATE = { type: 'create', comment: string };
type DELETE = { type: 'delete', id: number };
export type ActionTypes = CREATE | DELETE;
function dispatch(params: ActionTypes) {
Dispatcher.dispatch(params);
}
export default {
create(comment: string) {
dispatch({ type: 'create', comment });
},
delete(id: number) {
dispatch({ type: 'delete', id });
}
};
define actions and UnionTypes
dispatch function receives UnionTypes
dispatch’s args is always fulfill either
definition of UnionTypes