-
-
Notifications
You must be signed in to change notification settings - Fork 614
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(vanilla): new store listeners for devtools #1966
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 f57a26b:
|
Size Change: +619 B (+1%) Total Size: 66.9 kB
ℹ️ View Unchanged
|
@arjunvegda check out the new one! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! The write and restore functionality is working as expected.
Is there a way to trigger write-async
when a promise is resolved? Reference PR #1920
Co-authored-by: Arjun Vegda <[email protected]>
Our change here is about store listeners. Promise resolution isn't in it. (Our mental model is, Jotai store doesn't care about promise values.) |
I get your perspective now! I considered promise values as a first-class citizen for Jotai, similar to any other non-promise value. So to me, it's natural to fire an event (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Yeah, only the exception is that it wraps a promise to match with react behavior, like |
@arjunvegda Can you try if/how |
This new API and access to
This might be a stretch, but it'd be even nicer [in the future] to pre-hook for writing as well, maybe |
tbh, I thought about So, an ideal way would wrap store. const store = devtools(createStore());
const App = () => {
return (
<Provider store={store}>
<DevTools store={store} />
{/* your app */}
</Provider>
);
};
// OR
const store = createStore();
const App = () => {
return (
<ProviderWithDevTools store={store}>
{/* your app */}
</ProviderWithDevTools>
);
}; This doesn't work with the default store, so we would need a hook for it. 🤔 (Yeah, I wonder if we can eliminate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [jotai](https://togithub.com/pmndrs/jotai) | [`2.1.0` -> `2.2.1`](https://renovatebot.com/diffs/npm/jotai/2.1.0/2.2.1) | [![age](https://badges.renovateapi.com/packages/npm/jotai/2.2.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/jotai/2.2.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/jotai/2.2.1/compatibility-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/jotai/2.2.1/confidence-slim/2.1.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pmndrs/jotai (jotai)</summary> ### [`v2.2.1`](https://togithub.com/pmndrs/jotai/releases/tag/v2.2.1) [Compare Source](https://togithub.com/pmndrs/jotai/compare/v2.2.0...v2.2.1) This includes some improvements in `jotai/utils`. Especially, `unstable_unwrap` is getting to be stable. ##### What's Changed - feat(utils/useHydrateAtoms) - Optionally rehydrate with force hydrate by [@​SariSabouh](https://togithub.com/SariSabouh) in [https://github.com/pmndrs/jotai/pull/1990](https://togithub.com/pmndrs/jotai/pull/1990) - fix(utils): revert atomWithStorage typing by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1994](https://togithub.com/pmndrs/jotai/pull/1994) - fix(utils): improve selectAtom typing by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1995](https://togithub.com/pmndrs/jotai/pull/1995) - fix(utils): improve unstable_unwrap for sometimes async atom by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1996](https://togithub.com/pmndrs/jotai/pull/1996) - fix(utils): unstable_unwrap to support writable atom by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1997](https://togithub.com/pmndrs/jotai/pull/1997) ##### New Contributors - [@​SariSabouh](https://togithub.com/SariSabouh) made their first contribution in [https://github.com/pmndrs/jotai/pull/1990](https://togithub.com/pmndrs/jotai/pull/1990) **Full Changelog**: pmndrs/jotai@v2.2.0...v2.2.1 ### [`v2.2.0`](https://togithub.com/pmndrs/jotai/releases/tag/v2.2.0) [Compare Source](https://togithub.com/pmndrs/jotai/compare/v2.1.1...v2.2.0) It includes a few improvements. Some utils are rewritten as there was a misconception when migrating from v1. ESM builds are optimized for Vite users. #### Migration Guide for `jotai/utils` ##### `atomWithDefault` ```js // suppose we have this const asyncAtom = atom(() => Promise.resolve(1)) const countAtom = atomWithDefault((get) => get(asyncAtom)) // and in component const setCount = useSetAtom(countAtom) // previously, setCount((c) => c + 1) // it worked, but it will no longer work // instead, you need to do this setCount((countPromise) => countPromise.then((c) => c + 1)) ``` ##### `atomWithStorage` ```js // suppose we have async storage const storage = createJSONStorage(() => AsyncStorage) const countAtom = atomWithStorage('count-key', 0, storage) // in component const [count, setCount] = useAtom(countAom) // previously, countAtom is a sync atom, so you could update like this: setCount((c) => c + 1) // with the new version, it becomes async occasionally, so you need to resolve it: setCount(async (c) => (await c) + 1) ``` #### What's Changed - breaking(utils): predictable atomWithDefault by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1939](https://togithub.com/pmndrs/jotai/pull/1939) - breaking(utils): improve atomWithStorage by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1958](https://togithub.com/pmndrs/jotai/pull/1958) - feat(vanilla): new store listeners for devtools by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1966](https://togithub.com/pmndrs/jotai/pull/1966) - fix(build): mode env for "import" condition" by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1978](https://togithub.com/pmndrs/jotai/pull/1978) #### New Contributors - [@​reinierkaper-carewell](https://togithub.com/reinierkaper-carewell) made their first contribution in [https://github.com/pmndrs/jotai/pull/1980](https://togithub.com/pmndrs/jotai/pull/1980) **Full Changelog**: pmndrs/jotai@v2.1.1...v2.2.0 ### [`v2.1.1`](https://togithub.com/pmndrs/jotai/releases/tag/v2.1.1) [Compare Source](https://togithub.com/pmndrs/jotai/compare/v2.1.0...v2.1.1) This version fixes some issues in edge cases. #### What's Changed - fix(vanilla): Stable promise by [@​backbone87](https://togithub.com/backbone87) in [https://github.com/pmndrs/jotai/pull/1933](https://togithub.com/pmndrs/jotai/pull/1933) - fix(vanilla): update atoms with tree structure dependencies (regression from v1) by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1959](https://togithub.com/pmndrs/jotai/pull/1959) - fix: prefer PromiseLike where appropriate by [@​dai-shi](https://togithub.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/1967](https://togithub.com/pmndrs/jotai/pull/1967) #### New Contributors - [@​blissdev](https://togithub.com/blissdev) made their first contribution in [https://github.com/pmndrs/jotai/pull/1945](https://togithub.com/pmndrs/jotai/pull/1945) - [@​hwanyoungChoi](https://togithub.com/hwanyoungChoi) made their first contribution in [https://github.com/pmndrs/jotai/pull/1957](https://togithub.com/pmndrs/jotai/pull/1957) - [@​alexhad6](https://togithub.com/alexhad6) made their first contribution in [https://github.com/pmndrs/jotai/pull/1971](https://togithub.com/pmndrs/jotai/pull/1971) - [@​backbone87](https://togithub.com/backbone87) made their first contribution in [https://github.com/pmndrs/jotai/pull/1933](https://togithub.com/pmndrs/jotai/pull/1933) **Full Changelog**: pmndrs/jotai@v2.1.0...v2.1.1 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/sullivanpj/open-system).
This supersedes #1965.
Two improvements:
restore
.flushed
set.Also, we added the notion of "revision" which means we will probably keep improving/changing in the future.