-
Notifications
You must be signed in to change notification settings - Fork 1
Create process
LiQiang edited this page Aug 15, 2019
·
5 revisions
In my mind, redux action should be a simple action which triggers reducer and pass data. sending request and calculating some business logic makes the action complicated. So we could simplify the actions by Process
.
import { Process } from '@qlee/redux-functional';
import { taskActions } from './task-actions';
import * as TaskApi from './task-actions';
exprot const createTask = Process.create(
{addTask: taskActions.add}
({addTask}) => async (taskName: string) => {
if (!taskName) {
throw new Error('Task name can not be empty!');
}
const task: Task = await TaskApi.create(taskName);
return addTask(task);
}
);
import { default as React } from "react";
import { taskActions } from './task-actions';
import { ContainerAction } from '@qlee/redux-functional';
import { createTask } from './task-processes';
interface HomeComponentProps {
createTask: (name: string) => any
}
class HomeComponent extends React.Component<HomeComponentProps> {
...
}
const mapDispatchToProps = {
createTask,
};