Skip to content

Commit

Permalink
feat(): basic support for cycle diversity
Browse files Browse the repository at this point in the history
  • Loading branch information
TylorS committed Apr 27, 2016
1 parent 5882297 commit dddb7c4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
12 changes: 6 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h3 class='mb0 no-anchor'></h3>
<h2 id='createHref' class='mt0'>
createHref<span class='gray'>(path)</span>
</h2>
<p><a href='https://github.com/tylors/cyclic-router/blob/370e84ecd691ab7dc02299163f74083e908800fb/src/util.js#L52-L58'><code>src/util.js</code></a></p>
<p><a href='https://github.com/tylors/cyclic-router/blob/5882297b3060760f96f4cad1541ed4829be0f005/src/util.js#L25-L30'><code>src/util.js</code></a></p>



Expand Down Expand Up @@ -94,7 +94,7 @@ <h4>Returns</h4>
<h2 id='define' class='mt0'>
define<span class='gray'>(definitions)</span>
</h2>
<p><a href='https://github.com/tylors/cyclic-router/blob/370e84ecd691ab7dc02299163f74083e908800fb/src/definitionResolver.js#L60-L74'><code>src/definitionResolver.js</code></a></p>
<p><a href='https://github.com/tylors/cyclic-router/blob/5882297b3060760f96f4cad1541ed4829be0f005/src/definitionResolver.js#L18-L32'><code>src/definitionResolver.js</code></a></p>



Expand Down Expand Up @@ -132,7 +132,7 @@ <h4>Returns</h4>
<h2 id='makeRouterDriver' class='mt0'>
makeRouterDriver<span class='gray'>(historyArgs)</span>
</h2>
<p><a href='https://github.com/tylors/cyclic-router/blob/370e84ecd691ab7dc02299163f74083e908800fb/src/makeRouterDriver.js#L11-L27'><code>src/makeRouterDriver.js</code></a></p>
<p><a href='https://github.com/tylors/cyclic-router/blob/5882297b3060760f96f4cad1541ed4829be0f005/src/makeRouterDriver.js#L12-L32'><code>src/makeRouterDriver.js</code></a></p>



Expand Down Expand Up @@ -164,7 +164,7 @@ <h4>Returns</h4>
<h2 id='path' class='mt0'>
path<span class='gray'>(pathname)</span>
</h2>
<p><a href='https://github.com/tylors/cyclic-router/blob/370e84ecd691ab7dc02299163f74083e908800fb/src/pathFilter.js#L43-L49'><code>src/pathFilter.js</code></a></p>
<p><a href='https://github.com/tylors/cyclic-router/blob/5882297b3060760f96f4cad1541ed4829be0f005/src/pathFilter.js#L21-L27'><code>src/pathFilter.js</code></a></p>



Expand Down Expand Up @@ -195,7 +195,7 @@ <h4>Returns</h4>
<h2 id='routerAPI' class='mt0'>
routerAPI<span class='gray'></span>
</h2>
<p><a href='https://github.com/tylors/cyclic-router/blob/370e84ecd691ab7dc02299163f74083e908800fb/src/api.js#L37-L43'><code>src/api.js</code></a></p>
<p><a href='https://github.com/tylors/cyclic-router/blob/5882297b3060760f96f4cad1541ed4829be0f005/src/api.js#L24-L30'><code>src/api.js</code></a></p>



Expand Down Expand Up @@ -258,7 +258,7 @@ <h4>Properties</h4>
<h2 id='routerDriver' class='mt0'>
routerDriver<span class='gray'>(sink$)</span>
</h2>
<p><a href='https://github.com/tylors/cyclic-router/blob/370e84ecd691ab7dc02299163f74083e908800fb/src/makeRouterDriver.js#L23-L26'><code>src/makeRouterDriver.js</code></a></p>
<p><a href='https://github.com/tylors/cyclic-router/blob/5882297b3060760f96f4cad1541ed4829be0f005/src/makeRouterDriver.js#L24-L28'><code>src/makeRouterDriver.js</code></a></p>



Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"scripts": {
"docs": "rm -rf docs && mkdir docs && documentation build -f 'html' -g -o docs/ src/*.js",
"lint": "eslint src/",
"premocha": "babel-node ./buildTests.js",
"mocha": "mocha test/bundle.js",
"postmocha": "rm test/bundle.js",
"mocha": "mocha -r babel-register test/index.js",
"test": "npm run lint && npm run mocha",
"lib": "babel --presets es2015 src/ -d lib/",
"prepublish": "npm run lib"
Expand All @@ -32,11 +30,13 @@
},
"homepage": "https://github.com/tylors/cyclic-router#readme",
"devDependencies": {
"@cycle/xstream-adapter": "^1.0.2",
"assert": "^1.3.0",
"babel-cli": "^6.6.5",
"babel-core": "^6.7.2",
"babel-eslint": "^5.0.0",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.7.2",
"babelify": "^7.2.0",
"browserify": "^13.0.0",
"documentation": "^4.0.0-beta",
Expand All @@ -47,10 +47,15 @@
"history": "^2.0.1",
"mocha": "^2.4.5",
"rx": "^4.1.0",
"testem": "^1.5.0"
"testem": "^1.5.0",
"xstream": "^1.1.1"
},
"dependencies": {
"@cycle/history": "^2.0.0",
"@cycle/history": "^3.0.4",
"@cycle/rx-adapter": "^1.0.3",
"switch-path": "^1.1.5"
},
"perrDependencies": {
"rx": "^4.1.0"
}
}
11 changes: 8 additions & 3 deletions src/makeRouterDriver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {createAPI} from './api'
import {makeHistoryDriver} from '@cycle/history'
import RxAdapter from '@cycle/rx-adapter'

/**
* Instantiates an new router driver function using the same arguments required
Expand All @@ -20,10 +21,14 @@ function makeRouterDriver(...historyArgs) {
* history driver would expect.
* @return {routerAPI}
*/
return function routerDriver(sink$) {
const history$ = historyDriver(sink$)
return createAPI(history$.share(), [], history$.createHref)
function routerDriver(sink$, runSA) {
const history$ = historyDriver(sink$, runSA)
const rxHistory$ = RxAdapter.adapt(history$, runSA.streamSubscribe)
return createAPI(rxHistory$.share(), [], history$.createHref)
}

routerDriver.streamAdapter = RxAdapter
return routerDriver
}

export {makeRouterDriver}
28 changes: 15 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint max-nested-callbacks: 0 */
/*global describe, it */
import assert from 'assert'
import xs from 'xstream'
import XSAdapter from '@cycle/xstream-adapter'
import {Observable} from 'rx'
import {makeRouterDriver, createServerHistory} from '../src'

Expand All @@ -18,7 +20,7 @@ describe('Cyclic Router', () => {
'`createHref` and `dispose`',
() => {
const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.just('/'))
const router = makeRouterDriver(history)(xs.of('/'), XSAdapter)
assert.notStrictEqual(router.path, null)
assert.strictEqual(typeof router.path, 'function')
assert.notStrictEqual(router.define, null)
Expand All @@ -39,7 +41,7 @@ describe('Cyclic Router', () => {
'`createHref` and `dispose`',
() => {
const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.just('/'))
const router = makeRouterDriver(history)(xs.of('/'), XSAdapter)
.path('/')
assert.notStrictEqual(router.path, null)
assert.strictEqual(typeof router.path, 'function')
Expand All @@ -60,7 +62,7 @@ describe('Cyclic Router', () => {
'/path/that/is/correct',
]
const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
.path('/path')

router.observable.subscribe((location) => {
Expand All @@ -77,7 +79,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
.path('/some').path('/really').path('/really').path('/deeply')
.path('/nested').path('/route').path('/that')

Expand All @@ -95,7 +97,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
.path('/some').path('/really').path('/really').path('/deeply')
.path('/nested').path('/route').path('/that')

Expand All @@ -116,7 +118,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
.path('/some').path('/really').path('/really').path('/deeply')
.path('/nested').path('/route').path('/that')

Expand All @@ -131,7 +133,7 @@ describe('Cyclic Router', () => {
'`createHref` and `dispose`',
() => {
const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.just('/'))
const router = makeRouterDriver(history)(xs.of('/'), XSAdapter)
.define({})
assert.strictEqual(router instanceof Observable, true)
assert.strictEqual(typeof router.subscribe, 'function')
Expand All @@ -151,7 +153,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
const match$ = router.define(defintion)

match$.subscribe(({path, value, location}) => {
Expand All @@ -175,7 +177,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
const match$ = router.path('/some').path('/nested').define(defintion)

match$.subscribe(({path, value, location}) => {
Expand All @@ -201,7 +203,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
const match$ = router.path('/some').path('/nested').define(definition)

match$.subscribe(({path, value, location}) => {
Expand All @@ -226,7 +228,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
const match$ = router
.path('/some').path('/nested').define(defintion)

Expand All @@ -251,7 +253,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
const match$ = router
.path('/some').path('/nested').define(defintion)

Expand All @@ -277,7 +279,7 @@ describe('Cyclic Router', () => {
]

const history = createServerHistory()
const router = makeRouterDriver(history)(Observable.from(routes))
const router = makeRouterDriver(history)(xs.fromArray(routes), XSAdapter)
const match$ = router.path('/some').path('/nested').define(definition)

match$.dispose()
Expand Down

0 comments on commit dddb7c4

Please sign in to comment.