Skip to content
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

lastMatch should depend on isExact as well #345

Merged
merged 1 commit into from
Mar 14, 2020
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
2 changes: 1 addition & 1 deletion src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createSelectors = (structure) => {
}
lastPathname = pathname
const match = matchPath(pathname, path)
if (!match || !lastMatch || match.url !== lastMatch.url) {
if (!match || !lastMatch || match.url !== lastMatch.url || match.isExact !== lastMatch.isExact) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about the reason for comparing isExact here? So, we won't forget in the future.

lastMatch = match
}

Expand Down
13 changes: 8 additions & 5 deletions test/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ describe("selectors", () => {

it("does not update if the match is the same", () => {
const matchSelector = createMatchSelector("/")
store.dispatch(push('test1'))
const match = matchSelector(store.getState())
store.dispatch(push('test2'))
const expectedMatch = matchSelector(store.getState())
expect(match).toBe(expectedMatch)
const match1 = matchSelector(store.getState())
store.dispatch(push('/test1'))
const match2 = matchSelector(store.getState())
store.dispatch(push('/test2'))
const match3 = matchSelector(store.getState())
expect(match1).not.toBe(match2)
expect(match1).not.toBe(match3)
expect(match2).toEqual(match3)
})

it("updates if the match is different", () => {
Expand Down