* setItem migrated from asyn/await to promise
* setItem is more cleaner now
* rehydrate on initial state migrated to promise 🔥
* a tiny bug fixed in middleware
* .size-snapshot.json update
* don't invoke serialize when storage is undefined
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* a makeThenable() used to mix sync/async thens
* toThenable() API finalized
* size snapshots updated
* Add tests for sync storage
* Fix loading the state from localStorage
* new snapshot
* types ✨ added to `toThenable()` 🎉🎉
* new size snapshot
* Update src/middleware.ts
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* remaining parts also migrated to `toThenable()`
* a clear explanation of sync storage workaround
* fix some inconsistencies
* some inconsistency fixed
* useless IIFE removed
* some bugs and types fixed
* stateFromStorage renamed to stateFromStorageInSync
* Wrap tests into describe()
* Make sure that test for async persist() actually tests an async middleware
* size snap shot updated
* Correctly handle version discrepancies with missing migrate functions
* Update src/middleware.ts
Co-authored-by: Anatole Lucet <anatole@hey.com>
* Fix test
* chages addressed in reviews applied
* chore: refactor
* fix: setItem can throw error in sync
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: Benjamin Arbogast <benjamin.arbogast@gmail.com>
Co-authored-by: Anatole Lucet <anatole@hey.com>
Co-authored-by: daishi <daishi@axlight.com>
* (types): improve types for setState
allow for passing multiple key generics to PartialState; this will make sure that we can have paths in the PartialState setter function that return different keys
* (types): improve types for setState
replace `name` with `something`. for some reason, the property `name` does not yield errors :/
* (types): improve types for setState
streamline generic default values in middleware.ts with those in vanilla.ts
* (types): improve types for setState
use generic type S instead of State (S extends State)
* Make selector optional in zustand/vanilla
This type better reflects the optional nature of the parameter.
* Remove unnecessary line
* Fix type inference, still allow for optional selector type
* Remove optional from state slice type
* Remove semis
* Update vanilla.ts
* Putting it back
* context utils for SSR
* move useIsomorphicLayoutEffect to new file
* added build commands
* 1. remove the useEffect we dont need anymore 2. wrap context and hook into createZustand() function, but keep defaults
* issue #182 - changed name to createContext and useStore + added tests
* remove default Provider
* use alias to index file
* change 'createState' prop to 'initialStore'
that accepts useStore func/object from create().
This is needed as store access is needed for merging/memoizing, in next.js integration
* updated tests
* code review changes
* snapshot update
* add a section in readme
* chore imports and so on
Co-authored-by: daishi <daishi@axlight.com>
* Remove undesired index signature
* Use type assertion
* Update TypeScript readme
* Update TypeScript readme
* Replace Record with object
* Remove unnecessary keyof
* Minor fixes
* (types): improve types for setState
instead of using Partial, which would allow setting every field to undefined, we infer the types of the values depending on the keys passed into the set function
* (types): improve types for setState
add code comment to clarify why we are using Pick<T, K> | T
* (types): improve types for setState
apply the same changes we did for SetState also to namedSet for the devtools middleware
* (types): improve types for setState
tests for the partial logic
* empty commit
Co-authored-by: daishi <daishi@axlight.com>
* feat(persist): add tests
* feat(persist): can throw persist setItem error
* feat(persist): can throw rehydrate error
* feat(persist): can migrate persisted state and throw error
* chore: push size-snapshot
* fix(vanilla): add Promise to return type of SetState
* fix(persist): merge onRehydrateError with onRehydrateStorage
* fix(persist): revert async setState back to sync
* fix(persist): change persistedState type to any
* fix(persist): refactor storage object in tests
* fixed an issue in type infering while using eq function in hooks
* moving back quotes removed by autoformatter
* tweaked test and run linter
* Update tests/basic.test.tsx
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
* Hide warning when not run in browser (middleware)
I recently started using Zustand with next.js for my client-side state. In order to better debug/track the state, I've also started using the devtools middleware. This works fine on the client-side (in the browser), but results in lots of `console.warn` lines server-side (in the terminal when running the development server) stating "Please install/enable Redux devtools extension", which can obscure actual messages at times due to the number of times it is output. As the server side rendering happens outside of a browser, it seems a safe enough condition to add to this if statement.
The only other alternative I found to fix this locally is to assign the result of `create()` or `create(devtools())` conditionally, which results in a lot of duplicate code, as the devtools middleware requires extra parameters to the `set()` function (a name).
Please let me know if you're not happy with this solution (or if there are any drawbacks I haven't noticed).
I skipped opening an issue as well as the PR - if you prefer I open an issue as well, just drop me a comment.
* Fixed prettier complaint