246 Commits

Author SHA1 Message Date
zerofirework
5eaffff315
fix(middleware/persist): Merge storage value with the latest store state (#894)
* Merge storage value with the latest store state

When using zustand store with Provider and Context, it's possible to mutate the store state in an useEffect callback before hydration  creates `stateFromStorage`. It should merge the storage value with the latest store state instead of the config result since it can be out of date.

* fix tests

* Add test

* commit

Co-authored-by: Zero Liu <zerolxy@gmail.com>
2022-04-07 22:41:00 +09:00
Daishi Kato
a46f1fd871
fix(middleware/devtools): deprecate serialize.options (#828) 2022-02-28 11:12:44 +09:00
Devansh Jethmalani
52cc17a9fd
fix(context): revert removing overloads in UseContextStore (#817)
* fix(context): revert removing overloads in `UseContextStore`

Fixes #812

* add test

* fix lint
2022-02-28 10:52:25 +09:00
Devansh Jethmalani
a418fd7480
Migrations regarding higher kinded mutators for v4 (#772)
* add `Mutate` for migration path

* deprecate `PartialState`

* deprecate `StateSliceListener`

* add v4 version of `UseContextStore` for migration

* revert and deprecate `UseContextStore`

* subscribeWithSelector: fix deprecation message, add a test case

* subscribeWithSelector: fix overloads

* persist: deprecate `StoreApiWithPersist`

* subscribeWithSelector: update deprecation message

* redux: deprecate `StoreApiWithRedux`

* devtools: deprecate `StoreApiWithDevtools`

* migrate middleware tests

* update deprecation message to mention test file

* style

* don't export `WithPersist`
2022-02-11 08:23:24 +09:00
Daishi Kato
5b938fbbff
feat(build): use __DEV__ to control development mode (#789)
* feat(build): use __DEV__ to control development mode

* fix workflow

* missing env in systemjs build
2022-02-10 08:45:43 +09:00
Todd Williams
e90e8bc7b6
match vanilla StateCreator type in middleware/subscribeWithSelector (#787)
* match vanilla StateCreator type

Match
0ba3c24007/src/vanilla.ts (L50-L52)
to make subscribeWithSelector more useful with custom states.

Ran into this when trying to use subscribeWithSelector with
custom middleware that uses immer's WritableDraft on SetState

* apply changes for all middleware

Co-authored-by: Todd Williams <twilliams5@snapchat.com>
Co-authored-by: daishi <daishi@axlight.com>
2022-02-10 08:32:15 +09:00
Devansh Jethmalani
1b2560f25f
fix(devtools): don't show jsdoc deprecation warning when no options are passed (#781) 2022-02-10 08:31:38 +09:00
Devansh Jethmalani
2ddbd76a2c
devtools: deprecate passing name directly instead of an object (#731) 2021-12-24 16:10:36 +09:00
Daishi Kato
5b3b963181
fix(middleware): revert devtools extension connector with try-catch (#724)
* fix(middleware): revert devtools extension connector with try-catch

* add a test case

Co-authored-by: Devansh Jethmalani <devanshj@users.noreply.github.com>
2021-12-24 16:09:46 +09:00
Devansh Jethmalani
cb99a36c59
devtools: minor fixes (#720) 2021-12-23 10:03:07 +09:00
Daishi Kato
c54d1df87b
fix(middleware): devtools work in non-browser (#693)
* fix(middleware): devtools work in non-browser

* early return

* add a test

Co-authored-by: Devansh Jethmalani <devanshj@users.noreply.github.com>
2021-12-07 16:06:41 +09:00
Devansh Jethmalani
58baf27476
rewrite devtools (#675)
* rewrite `devtools`

* style

* merge state instead of replace, fix lint

* fix lint, don't use `Array.prototype.at`

* fix typo

* more lint fixing

* feat: allow setting state from the devtools

* deference dispatch in the store to use latest `api.dispatch`
that gets replaced in devtools middleware
2021-12-03 22:12:31 +09:00
Daishi Kato
30f5505cdb
chore(eslint): add recommended rules and etc (#678) 2021-11-25 22:33:59 +09:00
Daishi Kato
833f57ed13
refactor(middleware): split into multiple files (#664) 2021-11-16 22:22:16 +09:00
Daishi Kato
c319075d8c
refactor(core): extract react.ts from index.ts (#663) 2021-11-16 22:00:01 +09:00
Anatole Lucet
d28169d1b7
feat(middleware): add onFinishHydration to persist api (#646)
* feat(middleware): add onFinishHydration to persist api

* Update src/middleware.ts

* Update tests/persistSync.test.tsx

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2021-11-09 22:47:19 +09:00
Daishi Kato
62238d4920
fix(types): fix core types to better handle middleware types (#641)
* fix(types): fix core types to better handle middleware types

* fix eslint
2021-11-09 22:47:03 +09:00
Daishi Kato
2bc4de3c60
feat(middleware): devtools to patch api.setState with namedSet and fix middleware types (#634)
* wip: patch api.setState with devtools middleware

* wip: middleware type tests

* fix middleware types

* oh, that was it!

* fix a test, add comments
2021-11-04 07:30:38 +09:00
Daishi Kato
7fc3c49418
refactor(types): prefer type alias (#625) 2021-11-02 20:51:12 +09:00
Anatole Lucet
8665dd6cfe
feat(middleware): add persist api (#624)
* feat(persist middleware): add api

* workaround types

* add comment

Co-authored-by: daishi <daishi@axlight.com>
2021-11-02 20:46:55 +09:00
Daishi Kato
03e8eee55f
fix(core): useDebugValue in useStore (#622) 2021-11-02 20:46:23 +09:00
Daishi Kato
7e94455d27
fix(middleware): simplify middleware types and allow explicit typing (#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
2021-10-30 09:23:25 +09:00
Daishi Kato
ad318f3ebd
fix(middleware): types and devtools (#613)
* fix(middleware): types and devtools

* a fix

* make combine clean and always accept 3rd name arg

* revert fn name
2021-10-27 00:18:58 +09:00
M. Bagher Abiat
6bc21f555b
feat(middleware): devtools dispatch support (#608)
* feat: dispatch support

* chore: simpler code

* empty commit

Co-authored-by: daishi <daishi@axlight.com>
2021-10-27 00:04:25 +09:00
Daishi Kato
6ee3ed03bb
fix(context): custom store type for createContext (#606)
* fix(types): custon store type for createContext

* fix lint error

* empty commit
2021-10-27 00:04:05 +09:00
Daishi Kato
37ff965563
feat(middleware): subscribeWithSelector middleware (#603)
* feat(middleware): subscribeWithSelector middleware, deprecating the core feature

* update readme

* update readme
2021-10-21 22:51:10 +09:00
Daishi Kato
5f5527d590
fix(types): Rename from UseStore to UseBoundStore (#595) 2021-10-21 18:02:50 +09:00
Daishi Kato
10cb45c201
feat(types): better middleware support (#601)
* feat(types): better middleware support

* some more trial

* some more trial

* Revert "some more trial"

This reverts commit c54bf7cb75faa58e6df4325679ea5f815b594d01.

* some more trial

* some more trial

* some more trial

* some more trial

* Revert "some more trial"

This reverts commit 3aef9e229a54f18a901a1aea557cb05b46e8f2ab.

* some more trial

* Revert "some more trial"

This reverts commit fce0cb4c3e012adb35e5240e64d31cde3f7790f8.

* some more trial

* some more trial

* some more trial

* some more trial

* add redux middleware type test

* fix with type alias

* add devtools and redux combination test

* combine to support named set

* remove duplicated types
2021-10-21 17:51:24 +09:00
M. Bagher Abiat
aa31eb04fd
fix: jump state (#590) 2021-10-19 20:26:44 +09:00
Abraão Zaidan
e9a8eaa678
chore: export middleware type definitions (#588)
* chore: export middleware type definitions

* chore: export type PersistOptions in middleware

* Update src/middleware.ts

Co-authored-by: Abraão Zaidan <azc@lionx.com.br>
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2021-10-19 20:24:52 +09:00
Anatole Lucet
3d42979713
feat(persist): add persistFilter option & deprecate whitelist/blacklist (#463) 2021-10-07 21:38:18 +09:00
M. Bagher Abiat
478f53f7f9
init (#560) 2021-09-29 00:54:32 +09:00
Daishi Kato
2a412500f5
refactor: stricter tsconfig (#544)
* refactor: stricter tsconfig

* update typescript
2021-09-11 21:55:21 +09:00
marcoSven
bbd3793328
Allow optional REDUX DEVTOOLS "options" object (#540)
* Allow optional REDUX DEVTOOLS "options" object

## Why is this change needed?
Unable to display Maps/Sets

## How does it address the issue?
optional serialize date, regex, undefined, nan, infinity,
error, symbol, map & set

## breaking change prev "prefix" option
prefix?: string -> options?: { name?: string }

https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#serialize

https://github.com/pmndrs/zustand/issues/249

* backward compatible with "prefix" store name option

* Update readme.md
2021-08-26 22:53:40 +09:00
Daishi Kato
e47ea038fd
chore: update eslintrc and use react-jsx (#531) 2021-08-15 19:44:06 +09:00
Wojciech Adamek
d0d0091543
fix(context): Export UseContextStore interface (#492)
* Export UseStoreData interface

* Rename UseStoreData to UseContextStore
2021-07-14 08:41:00 +09:00
Wojciech Adamek
a4c7440032
Improve createContext's useStore types (#484)
* Improve createContext's useStore types

* Fix snapshot properties order

* Regenerate .size-snapshot.json

* Move UseStoreData interface to context.ts

* Remove UseStoreData interface export
2021-07-09 22:24:56 +09:00
Wojciech Adamek
7212d6efec
Revert Provider initialStore types (#486)
* Revert Provider initialStore types

* Add @deprecated directive to initialStore type

* Adjust deprecated comment

* empty commit

Co-authored-by: daishi <daishi@axlight.com>
2021-07-09 08:51:54 +09:00
Anatole Lucet
08f5d83393
fix(persist): #409 (#470)
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
2021-06-29 21:27:56 +09:00
Anatole Lucet
9774360900
fix(persist): #465 (#468) 2021-06-29 19:37:44 +09:00
Anatole Lucet
25a5e85c7d
fix(persist): merge function not working with async storages (#469) 2021-06-29 17:27:48 +09:00
Daishi Kato
6382cc34ae
hand transpile generator (#462) 2021-06-29 06:49:05 +09:00
Anatole Lucet
3ca105eb60
feat(persist): add a merge function option (#466) 2021-06-28 07:49:33 +09:00
Anatole Lucet
d57f12377d
fix(persist): #451 (#455) 2021-06-24 19:03:03 +09:00
Daishi Kato
52519a30d3
Fix/context create store (#447)
* Revert "chore: refactor zustand/context (#418)"

This reverts commit eb0a93b45d4e384533b4ef4237787745992aba3d.

* fix(context): createStore instead of initialStore

* update size snapshot
2021-06-22 20:52:17 +09:00
Daishi Kato
107d1f12d1
fix(context): stable storeApi (#444) 2021-06-21 20:06:53 +09:00
daishi
5f0ee2e441 update dev dependencies 2021-06-21 18:37:33 +09:00
Dương Tấn Huỳnh Phong
836aeaeccd
make type NamedSet compatible with type SetState (#441) 2021-06-20 22:33:29 +09:00
Benjamin Arbogast
3b4b2b5f3d
Pass correct argument to onRehydrateStorage when the migrate function is missing (#437)
When the state loaded from the storage would need to be migrated but the persist configuration doesn't contain a migrate function `onRehydrateStorage` would be called with the initial state. Now it is called with the state loaded from the storage, which in this case is assumed to be undefined.
2021-06-20 09:05:07 +09:00
Dương Tấn Huỳnh Phong
b6607f980f
export NamedSet type for combining with immer (#421) 2021-06-13 21:03:02 +09:00