From 289779fc69b01ea02724647981e697a77e4bc4f9 Mon Sep 17 00:00:00 2001 From: heebooo <1807941596@qq.com> Date: Sat, 3 Feb 2018 16:37:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E6=94=B6=E8=97=8Fst?= =?UTF-8?q?ore=E6=9C=89=E5=85=B3=E7=9A=84redux,=E6=96=B0=E5=BB=BA=E4=BA=86?= =?UTF-8?q?=E4=B8=89=E4=B8=AA=E5=B8=B8=E9=87=8F=EF=BC=8C=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AAaction=EF=BC=8C=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AAreducers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/store.js | 22 ++++++++++++++++++++++ src/actions/userinfo.js | 2 +- src/constants/store.js | 3 +++ src/constants/userinfo.js | 2 +- src/containers/City/index.js | 9 +++++---- src/containers/Detail/index.js | 19 +++++++++++++------ src/containers/Detail/subpage/Buy.js | 24 ++++++++++++++++++++++-- src/containers/Login/index.js | 8 ++++---- src/reducers/index.js | 4 +++- src/reducers/store.js | 21 +++++++++++++++++++++ 10 files changed, 95 insertions(+), 19 deletions(-) create mode 100644 src/actions/store.js create mode 100644 src/constants/store.js diff --git a/src/actions/store.js b/src/actions/store.js new file mode 100644 index 0000000..0d244ea --- /dev/null +++ b/src/actions/store.js @@ -0,0 +1,22 @@ +import * as actionTypes from '~constants/store'; + +export function update(data) { + return { + type: actionTypes.STORE_UPDATE, + data + }; +}; + +export function add(item) { + return { + type: actionTypes.STORE_ADD, + data: item + }; +}; + +export function rm(item) { + return { + type: actionTypes.STORE_RM, + data: item + }; +}; \ No newline at end of file diff --git a/src/actions/userinfo.js b/src/actions/userinfo.js index bc8d3bf..9d83147 100644 --- a/src/actions/userinfo.js +++ b/src/actions/userinfo.js @@ -5,4 +5,4 @@ export function update(data) { type: actionTypes.USERINFO_UPDATE, data } -} \ No newline at end of file +}; diff --git a/src/constants/store.js b/src/constants/store.js new file mode 100644 index 0000000..e8e7c06 --- /dev/null +++ b/src/constants/store.js @@ -0,0 +1,3 @@ +export const STORE_UPDATE = 'STORE_UPDATE'; // 更新 +export const STORE_ADD = 'STORE_ADD'; // 添加 +export const STORE_RM = 'STORE_RM'; // 删除 diff --git a/src/constants/userinfo.js b/src/constants/userinfo.js index a734993..4af6e0a 100644 --- a/src/constants/userinfo.js +++ b/src/constants/userinfo.js @@ -1 +1 @@ -export const USERINFO_UPDATE = 'userinfo_update'; \ No newline at end of file +export const USERINFO_UPDATE = 'USERINFO_UPDATE'; \ No newline at end of file diff --git a/src/containers/City/index.js b/src/containers/City/index.js index 5e50525..1230af2 100644 --- a/src/containers/City/index.js +++ b/src/containers/City/index.js @@ -1,7 +1,7 @@ import React, { PureComponent } from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; -import * as userInfoActionsFormOtherFile from '~actions/userinfo'; +import * as userInfoActionsFromOtherFile from '~actions/userinfo'; import LocalStore from '~util/localStore'; import { CITYNAME } from '~config/localStoreKey'; @@ -29,9 +29,10 @@ class City extends PureComponent { // 1.修改redux const userinfo = this.props.userinfo; - + const actions = this.props.userInfoActions; + userinfo.cityName = newCity; - this.props.userInfoActions.update(userinfo); + actions.update(userinfo); // 2.修改localStorage LocalStore.setItem(CITYNAME, newCity); @@ -51,7 +52,7 @@ const mapStateToProps = state => { const mapDispatchToProps = dispatch => { return { - userInfoActions: bindActionCreators(userInfoActionsFormOtherFile, dispatch) + userInfoActions: bindActionCreators(userInfoActionsFromOtherFile, dispatch) }; }; diff --git a/src/containers/Detail/index.js b/src/containers/Detail/index.js index 5ddc410..30d2b61 100644 --- a/src/containers/Detail/index.js +++ b/src/containers/Detail/index.js @@ -1,5 +1,8 @@ import React, { PureComponent } from 'react'; import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; + +import * as storeActionsFromFile from '~actions/store'; // 引入store收藏的action(3个) import Header from '~components/Header'; import Info from './subpage/Info'; // 商户详情 @@ -10,14 +13,18 @@ class Detail extends PureComponent { render() { // 获取商户id const id = this.props.match.params.id; - + console.log(this.props) return (