Skip to content

Commit

Permalink
add redux-immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
weizheng1992 committed Jan 2, 2019
1 parent 70b3c37 commit 043fcb3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@babel/polyfill": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"axios": "^0.18.0",
"immutable": "^4.0.0-rc.12",
"moment": "^2.22.2",
"nprogress": "^0.2.0",
"prop-types": "^15.6.2",
Expand All @@ -27,6 +28,7 @@
"react-swipeable-views-utils": "^0.13.0",
"react-transition-group": "^2.4.0",
"redux": "^4.0.1",
"redux-immutablejs": "^0.0.8",
"redux-logger": "^3.0.6",
"redux-saga": "^0.16.2",
"seamless-immutable": "^7.1.4",
Expand Down
3 changes: 2 additions & 1 deletion src/containers/HomeContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class HomeContainer extends React.Component {
}

const mapStateToProps = state => {
const { home } = state;
// console.log(state);
const { home } = state.toJS();
return {
home
};
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { HashRouter as Router } from "react-router-dom";
import { Provider } from "react-redux";
import { createStore } from "redux";
import App from "./config/router";
// import 'nprogress/nprogress.css'
import "./index.css";
Expand All @@ -11,6 +10,7 @@ import momentLocale from "moment/locale/zh-cn";
import { APIgetWechatUser } from "./config/api";
import storage from "./until/storage";
import rootSaga from './sagas/index';
import Immutable from 'immutable';
moment.updateLocale("zh-cn", momentLocale);
weChat.init();

Expand All @@ -25,8 +25,8 @@ if (!user) {
}
}


const store = configureStore();
const state = Immutable.fromJS({});
const store = configureStore(state);
store.runSaga(rootSaga);
const Index = () => (
<Provider store={store}>
Expand Down
38 changes: 17 additions & 21 deletions src/reducers/home.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import * as types from '../constants/ActionTypes';
import * as types from "../constants/ActionTypes";


const initialState = {
import { createReducer } from "redux-immutablejs";
import Immutable from "immutable";
const initialState = Immutable.fromJS({
loading: false,
entries:[]
};

export default function category(state = initialState, action) {
entries: []
});

switch (action.type) {
case types.FETCH_DETAIL_INFO:
return Object.assign({}, state, {
loading: true
});
case types.RECEIVE_DETAIL_INFO:
return Object.assign({}, state, {
loading: false,
entries: action.entries
});
default:
return state;
}
}
export default createReducer(initialState, {
[types.FETCH_DETAIL_INFO]: state =>
state.merge({
loading: true
}),
[types.RECEIVE_DETAIL_INFO]: (state, action) =>
state.merge({
loading: false,
entries: action.entries
})
});
3 changes: 2 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { combineReducers } from 'redux';
// import { combineReducers } from 'redux';
import { combineReducers } from 'redux-immutablejs';
import home from './home';

const rootReducer = combineReducers({
Expand Down
5 changes: 3 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { createStore, applyMiddleware } from "redux";
import createSagaMiddleware, { END } from 'redux-saga';
import rootReducer from "./reducers";



const middlewares = [];
const { logger } = require('redux-logger');

// configuring saga middleware
const sagaMiddleware = createSagaMiddleware();

Expand All @@ -22,4 +23,4 @@ export default function configureStore(initialState) {
store.close = () => store.dispatch(END);

return store;
}
}

0 comments on commit 043fcb3

Please sign in to comment.