Skip to content

Commit

Permalink
feat: Remove context usages (#107)
Browse files Browse the repository at this point in the history
React-Redux 6 compatibility by removing legacy context conventions
  • Loading branch information
cdoublev authored and ScriptedAlchemy committed Dec 23, 2018
1 parent dc38df7 commit 5a3f2bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
13 changes: 5 additions & 8 deletions src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const Link = (
{
to,
href,
location,
redirect,
replace,
tagName = 'a',
Expand All @@ -51,12 +52,10 @@ export const Link = (
target,
dispatch,
...props
}: Props,
{ store }: Context
}: Props
) => {
to = href || to // href is deprecated and will be removed in next major version

const location = selectLocationState(store.getState())
const { routesMap } = location
const url = toUrl(to, routesMap)
const handler = handlePress.bind(
Expand Down Expand Up @@ -98,11 +97,9 @@ export const Link = (
)
}

Link.contextTypes = {
store: PropTypes.object.isRequired
}

const connector: Connector<OwnProps, Props> = connect()
const mapState = state => ({ location: selectLocationState(state) })
const mapProps = dispatch => ({ dispatch })
const connector: Connector<OwnProps, Props> = connect(mapState, mapProps)

// $FlowIgnore
export default connector(Link)
22 changes: 6 additions & 16 deletions src/NavLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,14 @@ type OwnProps = {
}

type Props = {
dispatch: Function,
pathname: string
dispatch: Function
} & OwnProps

type Context = {
store: Store<*, *>
}

const NavLink = (
{
to,
href,
pathname,
location,
className,
style,
activeClassName = 'active',
Expand All @@ -58,18 +53,16 @@ const NavLink = (
strict,
isActive,
...props
}: Props,
{ store }: Context
}: Props
) => {
to = href || to

const options = getOptions()
const basename = options.basename ? options.basename : ''

const location = selectLocationState(store.getState())
const path = toUrl(to, location.routesMap).split('?')[0]

const match = matchPath(pathname, {
const match = matchPath(location.pathname, {
path: stripBasename(path, basename),
exact,
strict
Expand All @@ -89,16 +82,13 @@ const NavLink = (
className={combinedClassName}
style={combinedStyle}
aria-current={active && ariaCurrent}
location={location}
{...props}
/>
)
}

NavLink.contextTypes = {
store: PropTypes.object.isRequired
}

const mapState = state => ({ pathname: selectLocationState(state).pathname })
const mapState = state => ({ location: selectLocationState(state) })
const connector: Connector<OwnProps, Props> = connect(mapState)

// $FlowIgnore
Expand Down

0 comments on commit 5a3f2bb

Please # to comment.