-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed51a9c
commit 85c7916
Showing
16 changed files
with
314 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fetch from 'isomorphic-fetch'; | ||
import { API } from '../constants/globals'; | ||
|
||
export const REQUEST_EXAMPLE = 'REQUEST_EXAMPLE'; | ||
export const RECEIVE_EXAMPLE = 'RECEIVE_EXAMPLE'; | ||
export const INVALIDATE_EXAMPLE = 'INVALIDATE_EXAMPLE'; | ||
|
||
export function invalidateExample() { | ||
return { | ||
type: INVALIDATE_EXAMPLE, | ||
}; | ||
} | ||
|
||
function requestExample() { | ||
return { | ||
type: REQUEST_EXAMPLE, | ||
}; | ||
} | ||
|
||
function receiveExample(json) { | ||
return { | ||
type: RECEIVE_EXAMPLE, | ||
receiveAt: Date.now(), | ||
}; | ||
} | ||
|
||
function fetchData(data) { | ||
return dispatch => { | ||
dispatch(requestExample()); | ||
return fetch(API.EXAMPLE_URL) | ||
.then((req) => req.json()) | ||
.then((json) => { | ||
dispatch(receiveExample(json)); | ||
}); | ||
}; | ||
} | ||
|
||
function shouldFetchData(state) { | ||
const { example } = state; | ||
if (!example) { | ||
return true; | ||
} else if (example.isFetching) { | ||
return false; | ||
} | ||
return example.didInvalidate; | ||
} | ||
|
||
export function fetchExampleIfNeeded(data) { | ||
return (dispatch, getState) => { | ||
if (shouldFetchData(getState())) { | ||
return dispatch(fetchData(data)); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { invalidateExample, fetchExampleIfNeeded } from './example'; | ||
|
||
const actions = { | ||
invalidateExample, | ||
fetchExampleIfNeeded | ||
} | ||
|
||
export default actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import Administrator from '../container/Administrator'; | ||
|
||
const Admin = React.createClass({ | ||
render() { | ||
return ( | ||
<div> | ||
{ this.props.children || <Administrator /> } | ||
</div> | ||
); | ||
}, | ||
}); | ||
|
||
export default Admin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
|
||
var Administrator = React.createClass({ | ||
render: function() { | ||
return ( | ||
<div> | ||
<p>This is administrator page.</p> | ||
</div> | ||
) | ||
} | ||
}); | ||
|
||
module.exports = Administrator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
|
||
var Main = React.createClass({ | ||
render: function() { | ||
return ( | ||
<div> | ||
<p>Hello react && antd, :)</p> | ||
</div> | ||
) | ||
} | ||
}); | ||
|
||
module.exports = Main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
const ROOT_URL = "http://localhost:8080/"; | ||
|
||
module.exports = { | ||
API: { | ||
EXAMPLE_URL: ROOT_URL + 'EXAMPLE_PATH', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import Administrator from '../component/admin/Administrator'; | ||
import actions from '../actions'; | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
example: state.example | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return bindActionCreators(actions, dispatch); | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Administrator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
import Main from '../component/front/Main'; | ||
import actions from '../actions'; | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
example: state.example | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return bindActionCreators(actions, dispatch); | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,81 @@ | ||
import '../common/lib'; | ||
import App from '../component/App'; | ||
import ReactDOM from 'react-dom'; | ||
import 'babel-polyfill'; | ||
|
||
// redux-devtools | ||
import { createDevTools, persistState } from 'redux-devtools'; | ||
import LogMonitor from 'redux-devtools-log-monitor'; | ||
import DockMonitor from 'redux-devtools-dock-monitor'; | ||
// react | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
// router | ||
import { Router, Route, hashHistory, browserHistory, IndexRoute } from 'react-router'; | ||
// redux | ||
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'; | ||
import thunkMiddleware from 'redux-thunk' | ||
import createLogger from 'redux-logger' | ||
const loggerMiddleware = createLogger() | ||
|
||
import { Provider } from 'react-redux'; | ||
import { syncHistory } from 'react-router-redux'; | ||
// reducers | ||
import reducer from '../reducers'; | ||
|
||
const DevTools = createDevTools( | ||
<DockMonitor toggleVisibilityKey="ctrl-h" changePositionKey="ctrl-q"> | ||
<LogMonitor theme="tomorrow" preserveScrollTop={false} /> | ||
</DockMonitor> | ||
); | ||
// top entry | ||
import App from '../component/App'; | ||
import Admin from '../component/Admin'; | ||
|
||
// Sync dispatched route actions to the history | ||
const reduxRouterMiddleware = syncHistory(browserHistory); | ||
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware)(createStore); | ||
|
||
|
||
const enhancer = compose( | ||
applyMiddleware( | ||
thunkMiddleware, | ||
loggerMiddleware | ||
), | ||
DevTools.instrument(), | ||
persistState( | ||
window.location.href.match( | ||
/[?&]debug_session=([^&]+)\b/ | ||
) | ||
) | ||
); | ||
|
||
const store = createStore( | ||
reducer, | ||
enhancer | ||
) | ||
// Required for replaying actions from devtools to work | ||
reduxRouterMiddleware.listenForReplays(store) | ||
|
||
const routes = { | ||
path: '/', | ||
component: App, | ||
childRoutes: [ | ||
{ | ||
path: 'admin', | ||
component: Admin | ||
}, | ||
{ | ||
path: '*', | ||
component: App | ||
} | ||
] | ||
}; | ||
|
||
ReactDOM.render(<App />, document.getElementById('react-content')); | ||
render( | ||
<Provider store={store}> | ||
<div> | ||
<Router history={hashHistory} routes={routes} /> | ||
<DevTools /> | ||
</div> | ||
</Provider> | ||
, document.getElementById('react-content') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { REQUEST_EXAMPLE, RECEIVE_EXAMPLE, INVALIDATE_EXAMPLE } from '../actions/example'; | ||
|
||
export default function example(state = { | ||
isFetching: false, | ||
didInvalidate: true | ||
}, action) { | ||
switch (action.type) { | ||
case INVALIDATE_EXAMPLE: | ||
return Object.assign({}, state, { | ||
didInvalidate: true | ||
}) | ||
break; | ||
case REQUEST_EXAMPLE: | ||
return Object.assign({}, state, { | ||
isFetching: true, | ||
didInvalidate: false, | ||
}) | ||
break; | ||
case RECEIVE_EXAMPLE: | ||
return Object.assign({}, state, { | ||
isFetching: false, | ||
didInvalidate: false, | ||
lastUpdated: action.receiveAt | ||
}) | ||
break; | ||
default: | ||
return state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { combineReducers } from 'redux'; | ||
import { routeReducer } from 'react-router-redux'; | ||
import example from './example'; | ||
const rootReducer = combineReducers({ | ||
routing: routeReducer, | ||
example | ||
}); | ||
|
||
export default rootReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters