From 924e4c779a4299ec53cc3e592526967409469295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E9=95=BF=E6=B1=9F?= <343196441@qq.com> Date: Thu, 7 Jul 2016 13:34:11 +0800 Subject: [PATCH] =?UTF-8?q?reducer=E4=B8=BE=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app.js | 32 +++++++++++++------------- lib/home.js | 16 ++++++------- lib/index.js | 51 +++++++++++++++++++++++++++++++++++++++++ lib/reducers/reducer.js | 39 +++++++------------------------ 4 files changed, 83 insertions(+), 55 deletions(-) create mode 100644 lib/index.js diff --git a/lib/app.js b/lib/app.js index faf5ae2..91bede4 100644 --- a/lib/app.js +++ b/lib/app.js @@ -6,7 +6,7 @@ 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'; @@ -17,26 +17,26 @@ const history = useBasename(createHistory)({ queryKey: true }); -let store = createStore(reducer); +// const store = createStore(reducer); -// const createStoreWithMiddleware = applyMiddleware( -// thunk -// )(createStore); +const createStoreWithMiddleware = applyMiddleware( + thunk +)(createStore); -// const store = createStoreWithMiddleware(reducer); +const store = createStoreWithMiddleware(reducer); render( - - - - - - - - - - + + + + + + + + + + , document.getElementById('app') ) diff --git a/lib/home.js b/lib/home.js index c95b7c4..954a783 100644 --- a/lib/home.js +++ b/lib/home.js @@ -5,17 +5,17 @@ import {NavBottom,Slider,NewsList} from './common/common'; import {change} from './actions/index'; class Home extends Component { - constructor(props){ - super(props) - document.title = props.route.name - } + constructor(props){ + super(props) + document.title = props.route.name + } render(){ let dispatch = this.props.dispatch; return (
- - {this.props.show ? (
原生态
) : - (
+ + {this.props.show ? (
title状态1
) : + (

我的APP

@@ -36,7 +36,7 @@ class Home extends Component { -
+ ) } }; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..3d9da05 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,51 @@ +import {connect} from 'react-redux'; +import React,{Component} from 'react'; +import {NavBottom,Slider,NewsList} from './common/common'; + +import {change} from './actions/index'; + +// document.title = this.state.name; + + +class Index extends Component { + constructor(props){ + super(props) + document.title = props.route.name + } + render(){ + let dispatch = this.props.dispatch; + return ( +
+ + {this.props.show ? (
原生态
) : + (
+

+ 我的APP +

+
) + } + +
距离2016高考还有1000
+
+ +
+
最新动态
+ + + + +
+ ) + } +}; + +function select(state){ + return {show:state} +}; + +export default connect(select)(Index); diff --git a/lib/reducers/reducer.js b/lib/reducers/reducer.js index d780327..6269390 100644 --- a/lib/reducers/reducer.js +++ b/lib/reducers/reducer.js @@ -1,31 +1,8 @@ -// 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; - } -} \ No newline at end of file +export const reducer = (state=false,action)=>{ + switch(action.type){ + case 'CHANGE' : + return !state; + default : + return state; + } +}