Skip to content

feat(devtool): inferred action type#2987

Merged
dai-shi merged 6 commits intopmndrs:mainfrom
alimertcakar:feat-automatic-action-names
May 21, 2025
Merged

feat(devtool): inferred action type#2987
dai-shi merged 6 commits intopmndrs:mainfrom
alimertcakar:feat-automatic-action-names

Conversation

@alimertcakar
Copy link
Copy Markdown
Contributor

@alimertcakar alimertcakar commented Jan 30, 2025

Summary

image

With devtools() middleware, we can use Redux devtools extension to debug fired actions. But actions are shown as either "anonymous" or by the custom name we provided in set() function like: set(foo, undefined, "state/setCount").

It is really tedious to provide a action name for every set call. Wouldn't it be nice to have the option to have it default to a more meaningful name?

Now we can do that by passing inferActionName: true, to devtools options. It finds the the function name which called set() by reading the current stack.

This works for firefox,chrome and edge. (There isn't a redux devtools extension on Safari anyways)
In node.js it's displayed as Object.functionName instead of functionName, I don't think it matters as it's tests only.

Check List

  • pnpm run fix:format for formatting code and docs

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 30, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zustand-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 21, 2025 4:03am

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Jan 30, 2025

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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jan 30, 2025

demostarter

npm i https://pkg.pr.new/zustand@2987

commit: 8d3c89a

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Jan 30, 2025

This looks nice! I don't think we need inferActionName option, if this works reliably. Otherwise, I'd be a bit hesitant to merge.

@alimertcakar
Copy link
Copy Markdown
Contributor Author

This looks nice! I don't think we need inferActionName option, if this works reliably. Otherwise, I'd be a bit hesitant to merge.

Seems to work reliably on the mock project I created with a simple store.
I didn't test it on more complex projects. I can't get pnpm link --global zustand to work. Failed to resolve entry for package "zustand". The package may have incorrect main/module/exports specified in its package.json.

Is there a guide on local development? I'd like to meddle with zustand in some real life projects if possible

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Feb 2, 2025

I'm not sure what's wrong, but you can use pkg-pr-new #2987 (comment) if you don't find a local solution.

Copy link
Copy Markdown
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.

Remove inferActionName option.

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented Mar 24, 2025

@alimertcakar Are you still around?

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented May 7, 2025

@alimertcakar I hope you have a chance to look at it.

@dbritto-dev
Copy link
Copy Markdown
Collaborator

@dai-shi I can take care of this

@dai-shi
Copy link
Copy Markdown
Member

dai-shi commented May 21, 2025

@dbritto-dev Alright, I'll wait for it.

@dbritto-dev dbritto-dev changed the title feat(devtools middleware) add automatic action name finding feat(devtool): add automatic action name finding May 21, 2025
@dbritto-dev dbritto-dev changed the title feat(devtool): add automatic action name finding feat(devtool): inferred action type May 21, 2025
@dbritto-dev
Copy link
Copy Markdown
Collaborator

@dai-shi all yours

Copy link
Copy Markdown
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

@dai-shi dai-shi merged commit 670b60e into pmndrs:main May 21, 2025
31 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