Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
working examples route
Browse files Browse the repository at this point in the history
  • Loading branch information
cellog committed May 1, 2017
1 parent 195d433 commit 9758499
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 4 deletions.
28 changes: 25 additions & 3 deletions docs/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { Component } from 'react'
import Routes from 'ion-router/Routes'
import Route from 'ion-router/Route'
import Link from 'ion-router/Link'

import './App.css'
import Example from './components/Example'
import Examples from './components/Examples'
import ExamplesToggle from './toggles/ExamplesToggle'
import * as actions from './redux/actions'

class App extends Component {
render() {
Expand All @@ -10,10 +16,26 @@ class App extends Component {
<h2>Welcome</h2>
</div>
<div className="App-intro">
<Example example="basic" />
<ul>
<li><Link route="examples">Examples</Link></li>
</ul>
<ExamplesToggle component={Examples} />
</div>
<Routes>
<Route name="home" path="/">
<Route
name="examples"
path="examples(/:example)"
stateFromParams={params => params}
paramsFromState={state => state}
updateState={{
example: name => actions.chooseExample(name)
}}
/>
</Route>
</Routes>
</div>
);
)
}
}

Expand Down
20 changes: 20 additions & 0 deletions docs/src/components/Examples.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { connect } from 'react-redux'
import Link from 'ion-router/Link'
import ExampleToggle from '../toggles/ExampleToggle'
import thing from './Example'

const Example = connect(state => ({
example: state.examples.example
}))(thing)

export default function Examples() {
return (
<div>
<ul>
<li><Link route="examples" example="basic">Basic</Link></li>
</ul>
<ExampleToggle component={Example} />
</div>
)
}
23 changes: 22 additions & 1 deletion docs/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
import { Provider, connect } from 'react-redux'
import makeRouter, { makeRouterMiddleware } from 'ion-router'
import routing from 'ion-router/reducer'
import examples from './redux/example'

import App from './App'
import './index.css'

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose // eslint-disable-line
const reducer = combineReducers({
routing,
examples
})


// set up the router and create the store
const routerMiddleware = makeRouterMiddleware()
const store = createStore(reducer, undefined,
composeEnhancers(applyMiddleware(routerMiddleware)))
makeRouter(connect, store)

ReactDOM.render(
<App />,
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);
8 changes: 8 additions & 0 deletions docs/src/redux/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as types from './types'

export function chooseExample(example) {
return {
type: types.CHOOSE_EXAMPLE,
payload: example
}
}
18 changes: 18 additions & 0 deletions docs/src/redux/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as types from './types'

const defaultState = {
example: false
}

export default function reducer(state = defaultState, action) {
if (!action || !action.type) return state
switch (action.type) {
case types.CHOOSE_EXAMPLE:
return {
...state,
example: action.payload
}
default:
return state
}
}
1 change: 1 addition & 0 deletions docs/src/redux/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CHOOSE_EXAMPLE = 'CHOOSE_EXAMPLE'
3 changes: 3 additions & 0 deletions docs/src/toggles/ExampleToggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Toggle from 'ion-router/Toggle'

export default Toggle(state => state.examples.example)
3 changes: 3 additions & 0 deletions docs/src/toggles/ExamplesToggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import RouteToggle from 'ion-router/RouteToggle'

export default RouteToggle('examples')

0 comments on commit 9758499

Please sign in to comment.