-
-
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
[BREAKING] selectAtom does not resolve promises internally #2435
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. |
786e1d6
to
786ac5b
Compare
Preview in LiveCodesLatest commit: 6b56e74
See documentations for usage instructions. |
ebe8d57
to
e2da3d6
Compare
e2da3d6
to
aed3de2
Compare
e36ad6d
to
765ca6e
Compare
1ce866e
to
dc54f36
Compare
dc54f36
to
2451afb
Compare
2451afb
to
70321c5
Compare
70321c5
to
d0c9f5e
Compare
0ee8c6a
to
486ff4f
Compare
486ff4f
to
4e0b201
Compare
4e0b201
to
6e8a052
Compare
6806b7d
to
74a96d5
Compare
const baseAtom = atom(0)
const selectedAtom = selectAtom(
baseAtom,
(v) => v,
(a, b) => a === b,
)
// gives
function selectAtom<number, number>(
anAtom: Atom<number>,
selector: (v: number, prevSlice?: number | undefined) => number,
equalityFn?: ((a: number, b: number) => boolean) | undefined
): Atom<number> const baseAtom = atom(Promise.resolve(0))
const selectedAtom = selectAtom(
baseAtom,
(v) => v,
(a, b) => a === b,
)
// gives
function selectAtom<Promise<number>, Promise<number>>(
anAtom: Atom<Promise<number>>,
selector: (v: Promise<number>, prevSlice?: Promise<number> | undefined) => Promise<number>,
equalityFn?: ((a: Promise<number>, b: Promise<number>) => boolean) | undefined
): Atom<Promise<number>>``` |
74a96d5
to
d1c6d03
Compare
d1c6d03
to
346d966
Compare
346d966
to
0efbca6
Compare
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.
Yay! Looks far cleaner and more maintainable.
0efbca6
to
0b69a1c
Compare
…r and prev values are synchronous
0b69a1c
to
d94e407
Compare
Would you please write a migration guide in the PR description? |
Related Issues or Discussions
https://discord.com/channels/740090768164651008/1213966054125084672
Summary
When selectAtom is based on an atom whose value was originally a promise but was later changed to a value, selectAtom would still return a promise. This is because the original calculation of slice is a promise, so all subsequent calculations of slice must also be promises.
[BREAKING] In this PR selectAtom does not internally resolve promises. Instead this must be handled outside of the utility.
Migration
selectAtom
selectAtom
will no longer internally unwrap promises. To migrate to the new api, use theunwrap
utility fromjotai/utils
package.Check List
yarn run prettier
for formatting code and docs