-
Notifications
You must be signed in to change notification settings - Fork 4
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(scope): A complete rewrite of ScopeProvider (#16, #17) #20
Conversation
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 93f87be:
|
Hi, I think you can become a maintainer of jotai-scope. |
This solution is still incomplete. I write another example 06 to illustrate it. When 06 get fixed, we can guarantee both write and read are correct. |
I see. You can change package.json if you want. |
src/ScopeProvider.tsx
Outdated
type Store = ReturnType<typeof getDefaultStore>; | ||
export const ScopeContext = createContext<readonly [GetStoreKey, Store]>([ | ||
(a) => a, | ||
getDefaultStore(), |
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.
Just a nit, but getDefaultStore
is designed with lazy initialization in mind, but this forces to initialize it at the module load.
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.
@@ -59,14 +62,15 @@ | |||
"eslint": "^8.52.0", | |||
"eslint-config-airbnb": "^19.0.4", | |||
"eslint-config-prettier": "^9.0.0", | |||
"eslint-import-resolver-typescript": "^3.6.1", |
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.
Added this resolver for eslint-plugin-import
@dai-shi any comments? |
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.
Thanks a lot for working on this.
It looks pretty clean.
Is it ready to release?
...args, | ||
); | ||
}, | ||
}), | ||
// eslint-disable-next-line camelcase | ||
unstable_is: (a: AnyAtom) => isSelfAtom(a, originalAtom), |
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.
Interesting to see that this doesn't use this
. Yeah, because it already know originalAtom.
Co-authored-by: Daishi Kato <[email protected]>
Yes, ready to release. |
Do you want to release? I can tell you my workflow. |
Hmmm, then would you please tell me the workflow? I'm interested in it. |
Seems to be:
|
|
fixes #16, #17
depends on pmndrs/jotai#2356
To give it a try, use [
pnpm add
,yarn add
,npm i
] https://pkg.csb.dev/pmndrs/jotai/commit/3b6440d1/jotaiRoot Cause Analysis
Take a look of this atom:
Note that the condition
myAtom === anAtom
evals to true, which means they are exactly the same atom. Then, whydispatch(action)
callsreducer(action)
, butset(anAtom, reducedValue)
directly updates the value ofanAtom
instead of callingreducer(reducedValue)
?The key is here: https://github.com/pmndrs/jotai/blob/b5c38081e922b56621c6da9b9c32ef3d0f46e4b3/src/vanilla/store.ts#L527,
a === atom
checkThe line (
a === atom
check) checks if an atom is setting itself, so instead of calling the setter again, it directly update the value.TODO