-
-
Notifications
You must be signed in to change notification settings - Fork 646
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(devtools): enabled option useAtomsDevtools #1076
feat(devtools): enabled option useAtomsDevtools #1076
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/jotai/CVgMg3mQqHUk2BTzcvpM6TZYs7HJ |
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 a17d4bc:
|
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.
first review
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.
second one!
src/devtools/useAtomsDevtools.ts
Outdated
@@ -117,18 +136,19 @@ export function useAtomsDevtools(name: string, scope?: Scope) { | |||
let extension: typeof window['__REDUX_DEVTOOLS_EXTENSION__'] | |||
|
|||
try { | |||
extension = window.__REDUX_DEVTOOLS_EXTENSION__ | |||
extension = | |||
((enabled ?? __DEV__) && window.__REDUX_DEVTOOLS_EXTENSION__) || undefined |
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.
Let's add | false
in L136 instead.
((enabled ?? __DEV__) && window.__REDUX_DEVTOOLS_EXTENSION__) || undefined | |
((enabled ?? __DEV__) && window.__REDUX_DEVTOOLS_EXTENSION__) |
src/devtools/useAtomsDevtools.ts
Outdated
console.warn('Please install/enable Redux devtools extension') | ||
} | ||
} | ||
|
||
if (!store[DEV_SUBSCRIBE_STATE]) { | ||
if (!store[DEV_SUBSCRIBE_STATE] && enabled && __DEV__) { | ||
throw new Error('useAtomsSnapshot can only be used in dev mode.') |
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.
We don't need this completely, right?
src/devtools/useAtomsDevtools.ts
Outdated
const ScopeContext = getScopeContext(scope) | ||
const { s: store, w: versionedWrite } = useContext(ScopeContext) | ||
|
||
if (!store[DEV_SUBSCRIBE_STATE]) { | ||
if (!store[DEV_SUBSCRIBE_STATE] && enabled && __DEV__) { |
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.
I still want the early return.
Which test fails? I mean it should only fail if enabled === false
, right? It should be a new test.
if (!store[DEV_SUBSCRIBE_STATE] && enabled && __DEV__) { | |
if (enabled === false) { | |
return | |
} | |
if (!store[DEV_SUBSCRIBE_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.
I completely forgot about this being a hook. We can't early return. That's really my bad. So sorry to have your time wasted. Added a commit: dc485b7
This PR tries to achieve what we achieved in pmndrs/zustand#880 so we can add an option called
enabled
for better testing/dev env friendly errors/warnings!This PR is for useAtomsDevtools, so we can make reviewing easier. after this, we'll try achieving this for other dev tools.