-
Notifications
You must be signed in to change notification settings - Fork 6
Add support for react-redux 6 and onwards #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3119953
chore(*): update various dependencies
elboman 054ecb8
chore(ConnectedUIRouter): better types
elboman 11bd675
feat(ConnectedUIRouter): support react-redux@^6.x
elboman 129e09b
chore(*): apply prettier and fix some types
elboman f4c8705
chore(*): update deps and tests
elboman e5c00a5
chore(travis): update node version
elboman 2e72623
Merge branch 'master' into support-react-redux-6
christopherthielen 8eecd7c
fix: update typings to fix typescript errors
christopherthielen 78b8029
fix: update all dependencies
christopherthielen 536dc9a
fix: update webpack config for latest webpack
christopherthielen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| export { createReduxPlugin } from './reduxPlugin'; | ||
| export { routerReducer } from './reducer'; | ||
| export { default as createRouterMiddleware } from './middleware'; | ||
| export { triggerTransition } from './actions'; | ||
| export { createReduxPlugin, ReduxPluginApplyFn } from "./reduxPlugin"; | ||
| export { routerReducer } from "./reducer"; | ||
| export { default as createRouterMiddleware } from "./middleware"; | ||
| export { triggerTransition } from "./actions"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| var Enzyme = require("enzyme"); | ||
| var Adapter = require("enzyme-adapter-react-15"); | ||
| var serializer = require('enzyme-to-json/serializer'); | ||
| var Adapter = require("enzyme-adapter-react-16"); | ||
|
|
||
| Enzyme.configure({ adapter: new Adapter() }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,43 @@ | ||
| import { servicesPlugin, UIRouter, UIRouterProps } from '@uirouter/react'; | ||
| import * as PropTypes from 'prop-types'; | ||
| import * as React from 'react'; | ||
|
|
||
| import { createReduxPlugin } from '../core'; | ||
|
|
||
| export class ConnectedUIRouter extends React.Component<UIRouterProps, any> { | ||
| reduxPlugin; | ||
| router; | ||
|
|
||
| static contextTypes = { | ||
| store: PropTypes.object, | ||
| }; | ||
|
|
||
| constructor(props, context) { | ||
| super(props, context); | ||
| this.reduxPlugin = createReduxPlugin(context.store); | ||
| this.router = props.router; | ||
| this.router.plugin(servicesPlugin); | ||
| props.plugins.forEach(plugin => this.router.plugin(plugin)); | ||
| this.router.plugin(this.reduxPlugin); | ||
| if (props.config) props.config(this.router); | ||
| (props.states || []).forEach(state => | ||
| this.router.stateRegistry.register(state) | ||
| import { servicesPlugin, UIRouter, UIRouterProps } from "@uirouter/react"; | ||
| import { ReactReduxContext } from "react-redux"; | ||
| import * as React from "react"; | ||
| import { useContext, useRef } from "react"; | ||
|
|
||
| import { createReduxPlugin } from "../core"; | ||
|
|
||
| interface ConnectedUIRouterProps extends UIRouterProps { | ||
| children: React.ReactElement; | ||
| } | ||
|
|
||
| export function ConnectedUIRouter({ | ||
| children, | ||
| router: routerFromProps, | ||
| plugins, | ||
| config, | ||
| states, | ||
| }: ConnectedUIRouterProps) { | ||
| const init = useRef(false); | ||
|
|
||
| const { store } = useContext(ReactReduxContext); | ||
| const router = useRef(routerFromProps); | ||
| const reduxPlugin = useRef(createReduxPlugin(store)); | ||
|
|
||
| // let's initialise the plugins and set up the router | ||
| if (init.current !== true) { | ||
| // services plugin is necessary for UIRouter to function | ||
| router.current.plugin(servicesPlugin); | ||
| // apply all the plugins that are passed via props | ||
| plugins.forEach(plugin => router.current.plugin(plugin)); | ||
| // apply the newly created redux plugin | ||
| router.current.plugin(reduxPlugin.current); | ||
|
|
||
| if (config) config(router.current); | ||
| (states || []).forEach(state => | ||
| router.current.stateRegistry.register(state) | ||
| ); | ||
| } | ||
|
|
||
| render() { | ||
| const { children } = this.props; | ||
| return <UIRouter router={this.router}>{children}</UIRouter>; | ||
| init.current = true; | ||
| } | ||
|
|
||
| return <UIRouter router={router.current}>{children}</UIRouter>; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are moving to
Hooksanyway, maybe you should convert this touseEffectto be compliant with the React docs.Docs of
useEffectsuggest using it for side effects etc. So it would be a good use-case for this code.It would look like below, with empty array as second parameter to ensure that it fires only once.
https://reactjs.org/docs/hooks-reference.html#useeffect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that is possible as the router would be initialized only after the initial render. As for me, the router should be set up synchronously, so the current implementation looks reasonable