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

feat(types): better middleware support #601

Merged
merged 20 commits into from
Oct 21, 2021

Conversation

dai-shi
Copy link
Member

@dai-shi dai-shi commented Oct 21, 2021

Okay, to be honest, I don't like the tricky typescript typing. middleware is very type unfriendly.
I wouldn't build the API with middleware in this typescript era. (see jotai and valtio.)
That said, we still want to have better TS support in zustand.
Even though this makes the code less maintainable, it's worth it.

(We should add more type tests and middleware behavior tests. Any volunteers?)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 21, 2021

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 69a078b:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration
Next.js Configuration

@github-actions
Copy link

github-actions bot commented Oct 21, 2021

Size Change: 0 B

Total Size: 9.88 kB

ℹ️ View Unchanged
Filename Size
dist/context.js 622 B
dist/esm/context.js 521 B
dist/esm/index.js 1.16 kB
dist/esm/middleware.js 2.21 kB
dist/esm/shallow.js 272 B
dist/esm/vanilla.js 473 B
dist/index.js 1.29 kB
dist/middleware.js 2.43 kB
dist/shallow.js 318 B
dist/vanilla.js 582 B

compressed-size-action

@dai-shi dai-shi linked an issue Oct 21, 2021 that may be closed by this pull request
@dai-shi dai-shi marked this pull request as ready for review October 21, 2021 08:14
src/index.ts Outdated
Comment on lines 28 to 31
setState: CustomStoreApi['setState']
getState: CustomStoreApi['getState']
subscribe: CustomStoreApi['subscribe']
destroy: CustomStoreApi['destroy']
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I'm not wrong, these four fields are already in CustomStoreApi, right?
Why not just remove these four lines?

Copy link
Member Author

@dai-shi dai-shi Oct 21, 2021

Choose a reason for hiding this comment

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

Nice catch. At a certain commit, it was interface which can't be merged with CustomStoreApi. Now, it's type alias, and we can remove them.

@dai-shi dai-shi merged commit 10cb45c into main Oct 21, 2021
@dai-shi dai-shi deleted the feat/types/better-middleware-support branch October 21, 2021 08:51
dai-shi added a commit that referenced this pull request Oct 30, 2021
…617)

* chore(tests): add a use case combining many middleware

* simplify middleware types and allow explicit typing reverting some of #601

* fix context tests

* prettier

* refine middleware type test for more coverage and readability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants