-
Notifications
You must be signed in to change notification settings - Fork 664
Add warning in development when a result function is x => x.
#645
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
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ae0a921:
|
EskiMojo14
left a comment
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.
haven't had a chance to look through this properly yet, but a few initial suggestions
|
BTW I only called it |
|
we couldn't come up with anything better for react-redux so i doubt we'll do so here :) noopCheck is fine imo |
How about |
|
I don't know how many more dev checks we'd add in the future, but I think we ought to consolidate this into a single combined setter function just in case we do add more, rather than adding a bunch of individual setters. I'm thinking something like Let me play with that a bit on this branch. |
Yeah, I agree. If I put them in different files, would that be problematic? |
|
I'm picturing having a singleton object with the current global check values, and the setter would loop over the incoming options and assign. (Could even do |
|
the "should run" check explicitly checks against "always" and "once" so any other values will just function the same as "never", which i think is okay |
|
@markerikson I think I get it, so it would look something like this: export type DevModeChecks = Record<
'inputStabilityCheck' | 'identityFunctionCheck',
DevModeCheckFrequency
>
const globalDevModeChecks: DevModeChecks = {
inputStabilityCheck: 'once',
identityFunctionCheck: 'once'
}
export const setGlobalDevModeChecks = (
devModeChecks: Partial<DevModeChecks>
) => {
Object.assign(globalDevModeChecks, devModeChecks)
}then inside and to set the values globally: it('disables check if global setting is changed', () => {
setGlobalDevModeChecks({ inputStabilityCheck: 'never' })
expect(addNums(1, 2)).toBe(3)
expect(unstableInput).toHaveBeenCalledTimes(1)
expect(consoleSpy).not.toHaveBeenCalled()
setGlobalDevModeChecks({ inputStabilityCheck: 'once' })
})This could actually work I think. It passed the tests. |
|
@markerikson I'm not too sure about the warning message in the console, do you think we can improve on it, or leave it as is? |
8774936 to
959e327
Compare
- Rename the types, functions and variables to identity function check, since noop is more like `() => {}` and identity is `x => x`
- Add `DevModeChecks`, a type representing the configuration for development mode checks. - Replace `inputStabilityCheck` and `identityFunctionCheck` inside `CreateSelectorOptions` with `devModeChecks`. - Add `DevModeChecksExecutionInfo`, a type representing execution information for development mode checks. - Add `setGlobalDevModeChecks`, a function allowing to override `globalDevModeChecks`. - Create devModeChecks folder. - Move each dev-mode-check to their own file. - Remove `shouldRunDevModeCheck` in favor of `getDevModeChecksExecutionInfo`. - Update unit tests to comply with these changes.
a772528 to
01792bc
Compare
This PR:
identityFunctionCheckto warn to the user if the result function returns its input. It has the same configuration options asinputStabilityCheck.identityFunctionCheck.identityFunctionCheck.identityFunctionChecktoREADME.DevModeChecks, a type representing the configuration for development mode checks.inputStabilityCheckandidentityFunctionCheckinsideCreateSelectorOptionswithdevModeChecks.DevModeChecksExecutionInfo, a type representing execution information for development mode checks.setGlobalDevModeChecks, a function allowing to overrideglobalDevModeChecks.shouldRunDevModeCheckin favor ofgetDevModeChecksExecutionInfo.READMEwith new dev-mode-check API.