-
Notifications
You must be signed in to change notification settings - Fork 33
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
supports: atom toString includes debugLabel in dev mode #156
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. |
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.
LGTM
3b1cd8e
to
c11a1bf
Compare
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 liked your version. Doesn't it work?
src/utils/useAtomsDevtools.ts
Outdated
@@ -8,8 +8,13 @@ import { getReduxExtension } from './redux-extension/getReduxExtension'; | |||
import { SnapshotOptions, useAtomsSnapshot } from './useAtomsSnapshot'; | |||
import { useGotoAtomsSnapshot } from './useGotoAtomsSnapshot'; | |||
|
|||
const atomToPrintable = (atom: AnyAtom) => | |||
atom.debugLabel ? `${atom}:${atom.debugLabel}` : `${atom}`; | |||
const atomToPrintable = (atom: AnyAtom) => { |
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 have copies of this function across the codebase, could you pls update those too or perhaps move it to a shared function somewhere in the internals?
https://github.com/search?q=repo%3Ajotaijs%2Fjotai-devtools%20atomToPrintable&type=code
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.
or perhaps move it to a shared function somewhere in the internals?
I think I like this option more.
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.
https://github.com/search?q=repo%3Ajotaijs%2Fjotai-devtools%20atomToPrintable&type=code
These are only the ones named as such. There may be more.
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.
Good point! There is one more to update then 😄
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 reviewed this list. I actually don't think any further changes are necessary.
- src/utils/useAtomsDevtools.ts#L11 - Changed in this PR
const atomToPrintable = (atom: AnyAtom) =>
atom.debugLabel ? `${atom}:${atom.debugLabel}` : `${atom}`;
- src/utils/useAtomsDebugValue.ts#L13 - Only outputs debugLabel, so not the same logic as src/utils/useAtomsDevtools.ts#L11
const atomToPrintable = (atom: Atom<unknown>) =>
atom.debugLabel || atom.toString();
- src/DevTools/utils/atom-to-printable.ts#L9 - Only outputs debugLabel, so not the same logic as src/utils/useAtomsDevtools.ts#L11
export const atomToPrintable = (atom: AnyAtom): string => {
return atom.debugLabel ? atom.debugLabel : `<unlabeled-${atom}>`;
};
...Rest are references to 1, 2, and 3 above.
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.
Good point! There is one more to update then 😄
- src/utils/useAtomDevtools.ts#L29 - Same concern. Only outputs debugLabel, so not the same logic as src/utils/useAtomsDevtools.ts#L11
const atomName = name || anAtom.debugLabel || anAtom.toString();
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.
@arjunvegda
I agree this logic should be centralized, but can we move centralizing print logic to another PR since it will change the underlying logic?
This PR is to accommodate pmndrs/jotai#2659 in jotai core so that it doesn't break devtools.
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.
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.
You're right! we can do a broader overhaul of how these labels are used in dev tools in other PRs.
src/utils/useAtomsDevtools.ts
Outdated
@@ -8,8 +8,13 @@ import { getReduxExtension } from './redux-extension/getReduxExtension'; | |||
import { SnapshotOptions, useAtomsSnapshot } from './useAtomsSnapshot'; | |||
import { useGotoAtomsSnapshot } from './useGotoAtomsSnapshot'; | |||
|
|||
const atomToPrintable = (atom: AnyAtom) => | |||
atom.debugLabel ? `${atom}:${atom.debugLabel}` : `${atom}`; | |||
const atomToPrintable = (atom: AnyAtom) => { |
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.
Any thoughts on updating the fallback to something like <unlabeled-${atom}>
🤔. We do it for the UI version but not really for the Redux and React DevTools version
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 like it, but let's move this logic change / centralization to a separate PR.
Yes it does. I'll go back to that one. |
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.
LGTM
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.
LGTM! I'll try to get this out in the coming weeks (with some other changes). Please LMK if you need it sooner.
Related:
pmndrs/jotai#2659