From 0196493ae0120e93f97ddd04f71ef17fee4f6df8 Mon Sep 17 00:00:00 2001 From: KJlmfe Date: Thu, 2 Aug 2018 21:51:28 +0800 Subject: [PATCH] refactor: connect,Form.create use decorator --- src/layouts/BasicLayout.js | 15 +++++++-------- src/routes/Forms/AdvancedForm.js | 12 ++++++------ src/routes/Forms/StepForm/Step1.js | 9 ++++----- src/routes/Forms/StepForm/Step3.js | 9 ++++----- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 0f17b4ec..4fcdac68 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -88,7 +88,13 @@ enquireScreen(b => { isMobile = b; }); -class BasicLayout extends React.PureComponent { +@connect(({ user, global = {}, loading }) => ({ + currentUser: user.currentUser, + collapsed: global.collapsed, + fetchingNotices: loading.effects['global/fetchNotices'], + notices: global.notices, +})) +export default class BasicLayout extends React.PureComponent { static childContextTypes = { location: PropTypes.object, breadcrumbNameMap: PropTypes.object, @@ -301,10 +307,3 @@ class BasicLayout extends React.PureComponent { ); } } - -export default connect(({ user, global = {}, loading }) => ({ - currentUser: user.currentUser, - collapsed: global.collapsed, - fetchingNotices: loading.effects['global/fetchNotices'], - notices: global.notices, -}))(BasicLayout); diff --git a/src/routes/Forms/AdvancedForm.js b/src/routes/Forms/AdvancedForm.js index 94bc3c54..5b5f03a1 100644 --- a/src/routes/Forms/AdvancedForm.js +++ b/src/routes/Forms/AdvancedForm.js @@ -57,7 +57,12 @@ const tableData = [ }, ]; -class AdvancedForm extends PureComponent { +@connect(({ global, loading }) => ({ + collapsed: global.collapsed, + submitting: loading.effects['form/submitAdvancedForm'], +})) +@Form.create() +export default class AdvancedForm extends PureComponent { render() { const { form, dispatch, submitting } = this.props; const { getFieldDecorator, validateFieldsAndScroll, getFieldsError } = form; @@ -277,8 +282,3 @@ class AdvancedForm extends PureComponent { ); } } - -export default connect(({ global, loading }) => ({ - collapsed: global.collapsed, - submitting: loading.effects['form/submitAdvancedForm'], -}))(Form.create()(AdvancedForm)); diff --git a/src/routes/Forms/StepForm/Step1.js b/src/routes/Forms/StepForm/Step1.js index 5082c1a3..03062009 100644 --- a/src/routes/Forms/StepForm/Step1.js +++ b/src/routes/Forms/StepForm/Step1.js @@ -15,8 +15,11 @@ const formItemLayout = { }, }; +@connect(({ form }) => ({ + data: form.step, +})) @Form.create() -class Step1 extends React.PureComponent { +export default class Step1 extends React.PureComponent { render() { const { form, dispatch, data } = this.props; const { getFieldDecorator, validateFields } = form; @@ -108,7 +111,3 @@ class Step1 extends React.PureComponent { ); } } - -export default connect(({ form }) => ({ - data: form.step, -}))(Step1); diff --git a/src/routes/Forms/StepForm/Step3.js b/src/routes/Forms/StepForm/Step3.js index 9a8d6d46..196e0155 100644 --- a/src/routes/Forms/StepForm/Step3.js +++ b/src/routes/Forms/StepForm/Step3.js @@ -5,7 +5,10 @@ import { routerRedux } from 'dva/router'; import Result from 'components/Result'; import styles from './style.less'; -class Step3 extends React.PureComponent { +@connect(({ form }) => ({ + data: form.step, +})) +export default class Step3 extends React.PureComponent { render() { const { dispatch, data } = this.props; const onFinish = () => { @@ -67,7 +70,3 @@ class Step3 extends React.PureComponent { ); } } - -export default connect(({ form }) => ({ - data: form.step, -}))(Step3); -- GitLab