-
Notifications
You must be signed in to change notification settings - Fork 592
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
[FEAT]: Add selectors #98
Conversation
abd4990
to
463ed5c
Compare
src/selectors.js
Outdated
|
||
const createSelectors = (structure) => { | ||
const { getIn, toJS } = structure | ||
|
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.
nit: No new line needed for variable declaration.
src/selectors.js
Outdated
const getAction = state => toJS(getIn(state, ['router', 'action'])) | ||
const createMatchSelector = path => { | ||
let lastPathname = null | ||
let lastMatch = null |
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.
nit: new line before return
.
const match = matchPath(pathname, path) | ||
if (!match || !lastMatch || match.url !== lastMatch.url) { | ||
lastMatch = match | ||
} |
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.
nit: new line before return
.
src/selectors.js
Outdated
|
||
const getLocation = state => toJS(getIn(state, ['router', 'location'])) | ||
const getAction = state => toJS(getIn(state, ['router', 'action'])) | ||
const createMatchSelector = path => { |
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.
Can you add some comments about the behavior of the matchSelector? So, it will be easier to understand for anyone who read the code. Ex. I need to read twice before I realized that lastPathname
and lastMatch
are inside a closure and their values are kept in memory, not re-initialized to null everytime.
test/selectors.test.js
Outdated
}) | ||
}) | ||
|
||
describe("getLocation", () => { |
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.
typo: getAction
test/selectors.test.js
Outdated
}) | ||
|
||
describe("getLocation", () => { | ||
it("gets the location from the state", () => { |
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.
ditto
expect(() => matchSelector(state)).not.toThrow() | ||
}) | ||
|
||
it("does not update if the match is the same", () => { |
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.
For all test cases, instead of comparing match1 with match2, I think it will be easier to understand if we compare each one against its expected value.
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.
Overall is awesome! Can you address some nits?
Hi @supasate ! Thanks for the review, I rushed this a bit when I created the PR, sorry about that. I have addressed all your comments, please let me know if this look "mergeable" now or if you want me to make more changes. |
LGTM. Thanks for your contribution! |
Hi and thanks for this library!
I'm migrating from react-router-redux and the only thing that I'm really missing is its selectors... Specially the
createMatchSelector
. So, I have taken the ones fromreact-router-redux
and I have migrated them (with their corresponding tests) so that they can work in this library.I would really appreciate it if you could add them to
connected-react-router
.