Skip to content

Commit

Permalink
整理reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
xcj-coding committed Jul 7, 2016
1 parent a21b647 commit ed5ea48
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
4 changes: 4 additions & 0 deletions lib/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function change(){
return {type: 'CHANGE'}
}

export const Loading = (loadingState) => {
return {
type: 'LOADING',
Expand Down
17 changes: 14 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, {Component, PropTypes} from 'react';
import {render} from 'react-dom';
import {createStore} from 'redux';
import {createStore,applyMiddleware} from 'redux';
import {Provider} from 'react-redux';
import thunk from 'redux-thunk';
import {createHistory, useBasename} from 'history';
import {Router,Route,Link,IndexRoute,Redirect } from 'react-router';

import {reducer} from './reducers/reducer';
import reducer from './reducers/reducer';

import HOME from './home';
import CRUISE from './cruise/index';
import NotFound from './common/notFound';

Expand All @@ -16,14 +18,23 @@ const history = useBasename(createHistory)({
});

let store = createStore(reducer);


// const createStoreWithMiddleware = applyMiddleware(
// thunk
// )(createStore);

// const store = createStoreWithMiddleware(reducer);

render(
<Provider store={store}>
<Router History={history}>
<Redirect from="/" to="/cruise" />
<Route path="cruise" component={CRUISE} name="游轮">
<Route path="/cruise" component={CRUISE} />
</Route>
<Route path="home" component={HOME} name="首页">
<Route path="/home" component={HOME} />
</Route>
<Route path="*" component={NotFound}/>
</Router>
</Provider>,
Expand Down
9 changes: 3 additions & 6 deletions lib/index.js → lib/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import {connect} from 'react-redux';
import React,{Component} from 'react';
import {NavBottom,Slider,NewsList} from './common/common';

import {change} from './action';
import {change} from './actions/index';

// document.title = this.state.name;


class Index extends Component {
class Home extends Component {
constructor(props){
super(props)
document.title = props.route.name
Expand Down Expand Up @@ -48,4 +45,4 @@ function select(state){
return {show:state}
};

export default connect(select)(Index);
export default connect(select)(Home);
27 changes: 25 additions & 2 deletions lib/reducers/reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
export const reducer = (state=false,action)=>{
// function counter(state = 0, action) {
// switch (action.type) {
// case 'INCREMENT':
// return state + 1;
// case 'DECREMENT':
// return state - 1;
// default:
// return state;
// }
// }

// export default counter;

// export const reducer = (state=false,action)=>{
// switch(action.type){
// case 'CHANGE' :
// return !state;
// default :
// return state;
// }
// }


export default function reducer(state,action){
switch(action.type){
case 'CHANGE' :
return !state;
default :
return state;
}
}
}

0 comments on commit ed5ea48

Please sign in to comment.