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

supports: atom toString includes debugLabel in dev mode #156

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

dmaskasky
Copy link
Member

Copy link

codesandbox-ci bot commented Jul 14, 2024

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.

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

LGTM

@dmaskasky dmaskasky force-pushed the atom-tostring branch 2 times, most recently from 3b1cd8e to c11a1bf Compare July 14, 2024 23:40
Copy link
Member

@dai-shi dai-shi left a 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?

@@ -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) => {
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member Author

@dmaskasky dmaskasky Jul 15, 2024

Choose a reason for hiding this comment

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

Copy link
Member

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 😄

Copy link
Member Author

@dmaskasky dmaskasky Jul 15, 2024

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.

  1. src/utils/useAtomsDevtools.ts#L11 - Changed in this PR
const atomToPrintable = (atom: AnyAtom) =>
  atom.debugLabel ? `${atom}:${atom.debugLabel}` : `${atom}`;
  1. 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();
  1. 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.

Copy link
Member Author

@dmaskasky dmaskasky Jul 15, 2024

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 😄

  1. 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();

Copy link
Member Author

@dmaskasky dmaskasky Jul 15, 2024

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

@@ -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) => {
Copy link
Member

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

Copy link
Member Author

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.

@dmaskasky
Copy link
Member Author

I liked your version. Doesn't it work?

Yes it does. I'll go back to that one.

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@arjunvegda arjunvegda left a 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.

@arjunvegda arjunvegda merged commit 609bd5a into jotaijs:main Jul 15, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants