Skip to content

Commit 370e84e

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 304af54 + 471a9ba commit 370e84e

File tree

21 files changed

+2347
-3940
lines changed

21 files changed

+2347
-3940
lines changed

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ The example found in the repo can be taken for a test-drive [here](http://tylors
3232
Here is a rundown of the `example` provided with this repo in the folder `/example`. This should allow a better understanding of how to use cyclic-router, for simplicity the styling has been removed here.
3333

3434
Starting in the file which has Cycle `run`, router driver needs to be created here along with the other drivers that you might be using.
35-
Looking at the imports below, [cyclic-history](https://github.com/tylors/cyclic-history) is being used instead of cycle-history.
3635

3736
```js
3837
// main.js
3938
import {run} from '@cycle/core'
4039
import {makeDOMDriver} from 'cycle-snabbdom'
41-
import {makeHistoryDriver} from 'cyclic-history'
4240
import {makeRouterDriver} from 'cyclic-router'
4341
import {createHashHistory} from 'history'
4442

@@ -47,12 +45,10 @@ import app from './app' // the function of your app
4745
run(app, {
4846
DOM: makeDOMDriver('#app'),
4947
// Notice how you need to feed in funcs from cyclic-history + history
50-
router: makeRouterDriver(makeHistoryDriver(createHashHistory())),
48+
router: makeRouterDriver(createHashHistory()),
5149
})
5250
```
5351

54-
In this instance we are using `cyclic-history` and `history` to deal with the history API, have a read of the history [docs](https://github.com/rackt/history/tree/master/docs#readme) to find out more information on how that all works.
55-
5652
###2.
5753

5854
App.js will be used as the place for showing the correct component in reference to current url (what you'd expect from a router!).
@@ -86,15 +82,15 @@ function view(sidebar, children) {
8682

8783
function App(sources) {
8884
const {router} = sources // get router out of sources
89-
const {path$, value$} = router.define(routes) // pass routes into the router
90-
const sidebar = Sidebar(sources, path$) // pass in sources and path$ into our sidebar
85+
const match$ = router.define(routes) // pass routes into the router
86+
const sidebar = Sidebar(sources, match$.pluck('path')) // pass in sources and path$ into our sidebar
9187

9288
// childrenDOM$ takes path$ from `router.define(routes)` above and zips it with values, here is where
9389
// the components swap in reference to the current url, notice router.path(path) is also passed in
9490
// for later use in nested routes.
9591
// This allows components to be nested without ever knowing they are actually nested.
96-
const childrenDOM$ = path$.zip(value$,
97-
(path, value) => value({...sources, router: router.path(path)}).DOM
92+
const childrenDOM$ = match$.map(
93+
({path, value}) => value({...sources, router: router.path(path)}).DOM
9894
)
9995

10096
return {
@@ -161,36 +157,42 @@ const routes = {
161157
'/compose': Compose,
162158
}
163159

164-
function view(createHref, path$, children) {
165-
return path$.map(() => {
166-
return div({},[
160+
function view(createHref) {
161+
return (children) =>
162+
div({}, [
167163
ul([
168164
li([
169-
a({props: {href: createHref('/why')},
170-
}, 'Why Cyclic Router?'),
165+
a({props: {href: createHref('/why')}}, 'Why Cyclic Router?'),
171166
]),
172167
li([
173-
a({props: {href: createHref('/built')},
174-
}, 'Built For Cycle.js'),
168+
a({props: {href: createHref('/built')}}, 'Built For Cycle.js'),
175169
]),
176170
li([
177-
a({props: {href: createHref('/compose')},
178-
}, 'Compose a Message'),
171+
a({props: {href: createHref('/compose')}}, 'Compose a Message'),
179172
]),
180173
]),
181174
children,
182175
])
183-
})
184176
}
185177

186178
function Inbox(sources) {
187179
const {router} = sources
188-
const {path$, value$} = router.define(routes)
180+
const match$ = router.define(routes)
189181

190-
const childrenDOM$ = value$.map(value => value(sources).DOM)
182+
const childrenDOM$ = match$.map(({value}) => value(sources).DOM)
191183

192-
return {DOM: view(router.createHref, path$, childrenDOM$)}
184+
return {DOM: childrenDOM$.map(view(router.createHref))}
193185
}
194186

195187
export default Inbox
196188
```
189+
190+
### Route Parameters
191+
192+
You can pass route parameters to your component by adding them to the component sources.
193+
194+
```js
195+
const routes = {
196+
'/:id': id => sources => YourComponent({props$: Observable.of({id}), ...sources})
197+
}
198+
```

docs/assets/anchor.js

Lines changed: 0 additions & 197 deletions
This file was deleted.

0 commit comments

Comments
 (0)