diff --git a/src/connect.js b/src/connect.js index c2d97c0..93349d9 100644 --- a/src/connect.js +++ b/src/connect.js @@ -32,15 +32,6 @@ export default ({scope, ...defaultProps} = {}) => (WrappedComponent) => { router: PropTypes.object, } - navigateToPath(path) { - // Check for the react-router context. - if (!this.context.router) { - return; - } - - this.context.router.push(path); - } - render() { const {components, renderMap} = this.props.___relocationState___; const { @@ -56,9 +47,7 @@ export default ({scope, ...defaultProps} = {}) => (WrappedComponent) => { ...component, render: renderMap[component.type], update: (props) => updateComponent(component.id, props), - remove: typeof component.removePath === 'string' - ? () => this.navigateToPath(component.removePath) - : () => removeComponent(component.id), + remove: () => removeComponent(component.id), }; if (scope) { diff --git a/src/index.js b/src/index.js index 2ef6cc1..88c790b 100644 --- a/src/index.js +++ b/src/index.js @@ -2,5 +2,4 @@ export {ADD_COMPONENT, REMOVE_COMPONENT} from './action'; export {addComponent, removeComponent} from './action'; export {default as relocation} from './connect'; export {default as reducer} from './reducer'; -export {default as createRelocationRouter} from './router'; export {default} from './connect'; diff --git a/src/reducer.js b/src/reducer.js index 5315bef..c5dd16a 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -4,7 +4,6 @@ import { SET_COMPONENT, UPDATE_COMPONENT, REMOVE_COMPONENT, - SET_ROUTE_COMPONENTS, } from './action'; export default combineReducers({ @@ -25,9 +24,4 @@ export default combineReducers({ state.filter((item) => item.id !== payload.id), }[action.type] || (() => state))(state, action), - - routeComponents: (state = [], action) => - action.type === SET_ROUTE_COMPONENTS - ? action.payload - : state, }); diff --git a/src/router.js b/src/router.js deleted file mode 100644 index 51a9d79..0000000 --- a/src/router.js +++ /dev/null @@ -1,111 +0,0 @@ -import {Component, PropTypes} from 'react'; -import {connect} from 'react-redux'; -import invariant from 'fbjs/lib/invariant'; - -import {setRouteComponents} from './action'; - -/** - * [description] - * @param {Function} formatPattern - The React Router `formatPattern` function. - * @returns {[type]} [description] - */ -export default (formatPattern) => { - invariant( - typeof formatPattern === 'function', - 'The `formatPattern` function from `react-redux` must be provided. ' + - 'Add `import {formatPattern} from "react-router"` and add it as the ' + - 'argument to your call to `createRelocationRouter`.' - ); - - const finalFormatPattern = typeof formatPattern === 'function' ? - formatPattern : (path) => path; - - class RelocationRouter extends Component { - static propTypes = { - routes: PropTypes.array.isRequired, - params: PropTypes.object.isRequired, - location: PropTypes.object.isRequired, - children: PropTypes.element.isRequired, - dispatch: PropTypes.func.isRequired, - }; - - // Use `componentWillMount` over `constructor` when calling `dispatch`. - // see: https://github.com/reactjs/react-redux/issues/129 - componentWillMount() { - this.updateRouteComponents(this.props); - } - - componentWillReceiveProps(nextProps) { - this.updateRouteComponents(nextProps); - } - - updateRouteComponents(props) { - const {routes, params, location} = props; - const {dispatch} = this.props; - - if (this.routes === params && this.prams === params) { - return; - } - - this.routes = routes; - this.params = params; - - const join = (base, path) => { - return base + (path && !/\/$/.test(base) ? '/' : '') + path; - }; - - const getFormattedPathName = (i) => { - let path = ''; - - for (let current = i; current >= 0; current--) { - const route = routes[current]; - - if (route && route.path) { - path = join(route.path, path); - if (/^\//.test(path)) { - return finalFormatPattern(path, params); - } - } - } - - return null; - }; - - const components = routes.reduce((components, route, i) => { - const {relocation} = route; - - if (relocation) { - components.push({ - // Use the formatted path that matched as the default id. - id: getFormattedPathName(i), - - // Merge component props with redux-router props. - props: { - ...relocation.props, - location, - params, - }, - - // If `route.relocation` is a string, assign it the type. Otherwise - // merge its values. - ...typeof relocation === 'string' ? {type: relocation} : relocation, - - removePath: relocation.removePath !== undefined ? - finalFormatPattern(relocation.removePath, params) : - getFormattedPathName(i - 1), - }); - } - - return components; - }, []); - - dispatch(setRouteComponents(components)); - } - - render() { - return this.props.children; - } - } - - return connect()(RelocationRouter); -}; diff --git a/src/selector.js b/src/selector.js index f73c302..36c370f 100644 --- a/src/selector.js +++ b/src/selector.js @@ -3,14 +3,5 @@ export const getRelocation = (state, props) => ? props.getRelocationState(state, props) : state.relocation; -export const getComponents = (state, props) => { - const routeComponents = getRelocation(state, props).routeComponents; - const components = getRelocation(state, props).components; - - // Concat components and route components uniquely by id. - return routeComponents - .filter(({id: routeId}) => - !components.filter(({id}) => id === routeId).length - ) - .concat(components); -}; +export const getComponents = (state, props) => + getRelocation(state, props).components; diff --git a/src/util.js b/src/util.js index 1dd2ce7..ee100af 100644 --- a/src/util.js +++ b/src/util.js @@ -15,7 +15,7 @@ export const componentShape = PropTypes.shape({ scope: PropTypes.string, props: PropTypes.object, remove: PropTypes.func, - removePath: PropTypes.string, + update: PropTypes.func, render: renderShape, });