Skip to content

docs(README): remove 'omit' in 'Overwriting state' section #3160

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

Merged

Conversation

sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Jun 23, 2025

Related Bug Reports or Discussions

Fixes #

Summary

Check List

  • pnpm run fix for formatting and linting code and docs

Copy link

vercel bot commented Jun 23, 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 Jun 25, 2025 0:36am

Copy link

codesandbox-ci bot commented Jun 23, 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.

Copy link

pkg-pr-new bot commented Jun 23, 2025

demostarter

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

commit: cedf51b

@sukvvon sukvvon force-pushed the docs/README-replace-lodash-with-es-toolkit branch from 6cf85c2 to ef95383 Compare June 23, 2025 05:13
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.

If we were to change the README, it would be nicer to avoid the library at all. Can you try?

README.md Outdated
@@ -125,7 +125,7 @@ const treats = useBearStore(
The `set` function has a second argument, `false` by default. Instead of merging, it will replace the state model. Be careful not to wipe out parts you rely on, like actions.

```jsx
import { omit } from 'es-toolkit/compat'
import omit from 'es-toolkit/compat/omit'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi

How does it look like?

Copy link
Member

Choose a reason for hiding this comment

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

No. I mean to avoid using the external library at all.

Copy link
Collaborator

@dbritto-dev dbritto-dev Jun 23, 2025

Choose a reason for hiding this comment

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

I'm down with you @dai-shi, we should remove the external lib in this case and replace it with Object.fromEntries(...) + Object.entries() + .filter()

README.md Outdated
Comment on lines 128 to 137
import omit from 'lodash-es/omit'
function omit(obj, keys) {
const result = { ...obj }

for (let i = 0; i < keys.length; i++) {
const key = keys[i]
delete result[key]
}

return result
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi, @dbritto-dev

How does it look like?

Choose a reason for hiding this comment

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

It looks like not FP, perhaps it should be like this:

const omit = keysToOmit => obj =>
  Object.fromEntries(
    Object.entries(obj).filter(([key]) => !keysToOmit.includes(key))
  );

Copy link
Contributor Author

@sukvvon sukvvon Jun 23, 2025

Choose a reason for hiding this comment

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

@GeoDaoyu

function omit(obj, keys) {
  return Object.fromEntries(
    Object.entries(obj).filter(([key]) => !keys.includes(key))
  )
}

I understand what you’re saying, but I’ve already taken browser compatibility into consideration for now.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't create a util function. Just do it in the store action in a simple way.

@sukvvon sukvvon force-pushed the docs/README-replace-lodash-with-es-toolkit branch from 05d7c65 to 8fb8fbe Compare June 23, 2025 14:29
@sukvvon sukvvon changed the title docs(README): replace 'lodash' with 'es-toolkit' in 'Overwriting state' section docs(README): replace 'lodash' with custom 'omit' implementation in 'Overwriting state' section Jun 23, 2025
@sukvvon sukvvon changed the title docs(README): replace 'lodash' with custom 'omit' implementation in 'Overwriting state' section docs(README): remove 'omit' in 'Overwriting state' section Jun 24, 2025
README.md Outdated
Comment on lines 128 to 137
import omit from 'lodash-es/omit'

const useFishStore = create((set) => ({
salmon: 1,
tuna: 2,
deleteEverything: () => set({}, true), // clears the entire store, actions included
deleteTuna: () => set((state) => omit(state, ['tuna']), true),
deleteTuna: () =>
set((state) => {
const { tuna, ...rest } = state
return rest
}, true),
}))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi

I reflected your opinion.

Copy link
Member

Choose a reason for hiding this comment

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

Cool. I'm not sure if we prefer this, but we could also do this.

set(({ tuna, ...rest }) => rest, true);

@dbritto-dev thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi

Sounds good. I reflected your opinion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dai-shi I'm down with you

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.

Thanks!!

@dai-shi dai-shi merged commit e639587 into pmndrs:main Jun 25, 2025
31 checks passed
@sukvvon sukvvon deleted the docs/README-replace-lodash-with-es-toolkit branch June 25, 2025 02:17
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.

4 participants