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

Commit

Permalink
prepare for initial release under new name
Browse files Browse the repository at this point in the history
  • Loading branch information
cellog committed Apr 19, 2017
1 parent e55249f commit f1432ae
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 190 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"dependencies": {
"history": "^4.5.1",
"invariant": "^2.2.2",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"prop-types": "^15.5.8",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"redux": "^3.6.0",
"redux-saga": "^0.14.2",
"route-parser": "0.0.5"
},
"devDependencies": {
Expand Down Expand Up @@ -84,7 +84,7 @@
"lolex": "^1.5.2",
"mocha": "^3.2.0",
"raw-loader": "^0.5.1",
"react-redux": "^5.0.2",
"react-redux": "^5.0.4",
"rimraf": "^2.5.4",
"selenium-webdriver": "^3.0.1",
"should": "^11.1.2",
Expand Down
3 changes: 2 additions & 1 deletion src/DisplaysChildren.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'

export default class DisplaysChildren extends Component {
static propTypes = {
Expand Down
20 changes: 16 additions & 4 deletions src/Link.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes, Component } from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import RouteParser from 'route-parser'
import invariant from 'invariant'

Expand Down Expand Up @@ -64,15 +65,26 @@ class Link extends Component {
const {
'@@__routes': unused, dispatch, href, replace, to, route, onClick, ...props // eslint-disable-line no-unused-vars
} = this.props
const validProps = [
'download', 'hrefLang', 'referrerPolicy', 'rel', 'target', 'type',
'id', 'accessKey', 'className', 'contentEditable', 'contextMenu', 'dir', 'draggable',
'hidden', 'itemID', 'itemProp', 'itemRef', 'itemScope', 'itemType', 'lang',
'spellCheck', 'style', 'tabIndex', 'title'
]
const aProps = Object.keys(props).reduce((newProps, key) => {
if (validProps.includes(key)) newProps[key] = props[key] // eslint-disable-line
if (key.slice(0, 5) === 'data-') newProps[key] = props[key] // eslint-disable-line
return newProps
}, {})
invariant(!href, 'href should not be passed to Link, use "to," "replace" or "route" (passed "%s")', href)
let landing = replace || to
let landing = replace || to || ''
if (this.route) {
landing = this.route.reverse(props)
} else if (landing.pathname) {
landing = `${landing.pathname}${'' + landing.search}${'' + landing.hash}` // eslint-disable-line prefer-template
}
return (
<a href={landing} onClick={this.click} {...props}>
<a href={landing} onClick={this.click} {...aProps}>
{this.props.children}
</a>
)
Expand All @@ -83,7 +95,7 @@ export { Link }

export const Placeholder = () => {
throw new Error('call connectLink with the connect function from react-redux to ' +
'initialize Link (see https://github.com/cellog/react-redux-saga-router/issues/1)')
'initialize Link (see https://github.com/cellog/ion-router/issues/1)')
}

let ConnectedLink = null
Expand Down
3 changes: 2 additions & 1 deletion src/Route.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Children, Component, PropTypes } from 'react'
import React, { Children, Component } from 'react'
import PropTypes from 'prop-types'

export function fake() {
return {}
Expand Down
3 changes: 2 additions & 1 deletion src/Routes.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes, Component, Children } from 'react'
import React, { Component, Children } from 'react'
import PropTypes from 'prop-types'
import * as actions from './actions'
import { onServer } from '.'

Expand Down
19 changes: 2 additions & 17 deletions src/Toggle.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react'
import React from 'react'
import PropTypes from 'prop-types'

import DisplaysChildren from './DisplaysChildren'

Expand Down Expand Up @@ -107,21 +108,5 @@ export default (isActive, loaded = () => true, componentLoadingMap = {}, debug =
names[item] = componentLoadingMap[item]
}
})

Toggle.propTypes = {
[names.component]: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
[names.loadingComponent]: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
loading: (props, propName) => {
if (Object.hasOwnProperty.call(props, 'loading') && !Object.hasOwnProperty.call(props, 'loadingComponent')) {
const name = props.component.displayName || props.component.name || 'Component'
if (!componentLoadingMap.loadingComponent) {
console.warn(`${propName} in Toggle:${name} should be loadingComponent for ion-router`) // eslint-disable-line
}
}
return null
},
[names.else]: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
children: PropTypes.any
}
return Toggle
}
10 changes: 5 additions & 5 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import * as enhancers from './enhancers'
export const filter = (enhancedRoutes, path) => name => enhancedRoutes[name]['@parser'].match(path)
export const diff = (main, second) => main.filter(name => second.indexOf(name) === -1)

export function template(s, params) {
return s.exitParams instanceof Function ?
{ ...s.exitParams(params) } : { ...s.exitParams }
}

export function changed(oldItems, newItems) {
return Object.keys({ ...newItems, ...oldItems })
.filter(key => !Object.prototype.hasOwnProperty.call(oldItems, key) ||
Expand Down Expand Up @@ -98,6 +93,11 @@ export function updateState(s, params, state) {
}
}

export function template(s, params) {
return s.exitParams instanceof Function ?
{ ...s.exitParams(params) } : { ...s.exitParams }
}

export const exitRoute = (state, enhanced, name) => {
const s = enhanced[name]
const params = s.params
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function routingReducer(reducers = state => ({ ...(state || {}) })) {
return (state, action) => {
if (!state) {
return {
...routerReducer(),
routing: routerReducer(),
...(reducers() || {})
}
}
Expand All @@ -58,8 +58,16 @@ export function routingReducer(reducers = state => ({ ...(state || {}) })) {
...state,
routing: routerReducer()
}
} else {
const routing = routerReducer(newState.routing, action)
if (routing !== newState.routing) {
newState = {
...newState,
routing
}
}
}
return reducers(routerReducer(newState, action), action)
return reducers(newState, action)
}
}

Expand Down
31 changes: 26 additions & 5 deletions test/Link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setEnhancedRoutes } from '../src'
import * as enhancers from '../src/enhancers'
import { renderComponent, connect } from './test_helper'

describe('react-redux-saga-router Link', () => {
describe('Link', () => {
it('dispatches replace', () => {
const dispatch = sinon.spy()
const component = renderComponent(Link, { dispatch, replace: '/hi' })
Expand All @@ -31,9 +31,9 @@ describe('react-redux-saga-router Link', () => {
})
it('renders placeholder', () => {
expect(() => {
renderComponent(ConnectLink, { to: '/hi' }, {}, true)
renderComponent(ConnectLink, { dispatch: () => null, to: '/hi' }, {}, true)
}).throws('call connectLink with the connect function from react-redux to ' +
'initialize Link (see https://github.com/cellog/react-redux-saga-router/issues/1)')
'initialize Link (see https://github.com/cellog/ion-router/issues/1)')
})
it('connectLink', () => {
const spy1 = sinon.spy()
Expand All @@ -56,14 +56,14 @@ describe('react-redux-saga-router Link', () => {
it('dispatches actions when initialized', () => {
const spy = sinon.spy()
connectLink(connect)
const [component, , log] = renderComponent(ConnectLink, { to: '/hi', onClick: spy }, {}, true)
const [component, , log] = renderComponent(ConnectLink, { dispatch: () => null, to: '/hi', onClick: spy }, {}, true)
component.find('a').trigger('click')
expect(log).eqls([push('/hi')])
expect(spy.called).is.true
})
it('errors (in dev) on href passed in', () => {
connectLink(connect)
expect(() => renderComponent(ConnectLink, { href: '/hi' }, {}, true))
expect(() => renderComponent(ConnectLink, { dispatch: () => null, href: '/hi' }, {}, true))
.throws('href should not be passed to Link, use "to," "replace" or "route" (passed "/hi")')
})
describe('generates the correct path when route option is used', () => {
Expand Down Expand Up @@ -150,4 +150,25 @@ describe('react-redux-saga-router Link', () => {
expect(component.find('a').props('href')).eqls('/there/baby')
})
})
it('only valid props are passed to the a tag', () => {
const component = renderComponent(Link, {
...[
'download', 'hrefLang', 'referrerPolicy', 'rel', 'target', 'type',
'id', 'accessKey', 'className', 'contentEditable', 'contextMenu', 'dir', 'draggable',
'hidden', 'itemID', 'itemProp', 'itemRef', 'itemScope', 'itemType', 'lang',
'spellCheck', 'style', 'tabIndex', 'title'
].reduce((coll, item) => ({ ...coll, [item]: {} }), {}),
'data-hi': 'there',
foo: 'bar',
to: 'hi',
dispatch: () => null,
})
expect(Object.keys(component.find('a').props())).eqls([
'href', 'onClick', 'download', 'hrefLang', 'referrerPolicy', 'rel', 'target', 'type',
'id', 'accessKey', 'className', 'contentEditable', 'contextMenu', 'dir', 'draggable',
'hidden', 'itemID', 'itemProp', 'itemRef', 'itemScope', 'itemType', 'lang',
'spellCheck', 'style', 'tabIndex', 'title',
'data-hi', 'children'
])
})
})
2 changes: 1 addition & 1 deletion test/Route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setEnhancedRoutes } from '../src'
import * as enhancers from '../src/enhancers'
import { renderComponent, connect } from './test_helper'

describe('react-redux-saga-router Route', () => {
describe('Route', () => {
const paramsFromState = state => ({
id: state.ensembleTypes.selectedEnsembleType ?
(state.ensembleTypes.selectedEnsembleType === true ? 'new' : state.ensembleTypes.selectedEnsembleType) :
Expand Down
9 changes: 5 additions & 4 deletions test/Routes.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import * as actions from '../src/actions'
import { setServer, onServer } from '../src'
import { renderComponent, connect } from './test_helper'

describe('react-redux-saga-router Routes', () => {
describe('Routes', () => {
let component, store, log // eslint-disable-line
function make(props = {}, Comp = ConnectedRoutes, state = {}) {
function make(props = {}, Comp = ConnectedRoutes, state = {}, mount = false) {
connectRoutes(connect)
const info = renderComponent(Comp, props, state, true)
const info = renderComponent(Comp, props, state, true, false, mount)
component = info[0]
store = info[1]
log = info[2]
Expand Down Expand Up @@ -54,13 +54,14 @@ describe('react-redux-saga-router Routes', () => {
}
</div>
)
make({ thing: true }, R)
make({ thing: true }, R, {}, true)
component.props({ thing: false })

expect(log).eqls([
actions.batchRoutes([{ name: 'foo', path: '/bar' }]),
actions.batchRemoveRoutes([{ name: 'foo', path: '/bar' }])
])
component.unmount()
})
it('passes in routes from state', () => {
const Thing = () => <div />
Expand Down
31 changes: 0 additions & 31 deletions test/Toggle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,35 +186,4 @@ describe('Toggle', () => {
})
})
})
describe('propTypes loading', () => {
let warn
beforeEach(() => {
connectToggle(connect)
warn = sinon.stub(console, 'warn')
})
afterEach(() => {
warn.restore()
})
it('loading proptype validation', () => {
const R = Toggle(() => true, () => true)
const F = () => null
const container = renderComponent(R, { // eslint-disable-line
loading: F,
component: F
})
expect(warn.called).is.true
expect(warn.args[0]).eqls(['loading in Toggle:F should be loadingComponent for ion-router'])
})
it('no error if componentMap is enabled', () => {
const R = Toggle(() => true, () => true, {
loadingComponent: 'foo'
})
const F = () => null
const container = renderComponent(R, { // eslint-disable-line
loading: F,
component: F
})
expect(warn.called).is.false
})
})
})
2 changes: 1 addition & 1 deletion test/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as actions from '../src/actions'
import * as types from '../src/types'


describe('react-redux-saga-router actions', () => {
describe('actions', () => {
it('push', () => {
expect(actions.push('/hi')).eqls({
type: types.ACTION,
Expand Down
2 changes: 1 addition & 1 deletion test/enhanced.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import RouteParser from 'route-parser'
import * as enhance from '../src/enhancers'

describe('react-redux-saga-router enhanced route store', () => {
describe('enhanced route store', () => {
it('fake', () => {
expect(enhance.fake('hi')).eqls({})
})
Expand Down
Loading

0 comments on commit f1432ae

Please sign in to comment.