Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: legacy context usages #107

Merged
merged 1 commit into from
Dec 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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