-
-
Notifications
You must be signed in to change notification settings - Fork 257
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
Code comments / architecture explanation #171
Comments
valtio has two kinds of proxies, for write and read. We intentionally separate them for hooks and concurrent react.
both kinds of proxies create nested proxies on demand (and that's a tough task, which makes code hard.) I guess you want to start from |
Thanks for that explanation. It's a good start and I encourage you to put that in a document or in the code comments and expand a lot more. It's your project of course, and if you feel the code is clear enough feel free to close this issue. |
Let me add some code comments and hope to get some feedback from you. I would say the code is not very readable without high level abstraction. |
Although I'm not sure how much is covered, #174 adds something. |
I'd add interaction and data flows to a .md file or in the comments. The change you put in are general details but for a person who doesn't know the code won't get much from. Since you're not having high level abstraction in the actual code, you can provide that abstraction through comments. Pretend you have no idea what anything is when documenting the code as a newbie like myself won't be able to connect the dots.
|
Hmm, it seems to me like code comments are not good for this goal, at least didn't work for me. Let's create a wiki page so that you can also work on it, like adding questions. Here we go: https://github.com/pmndrs/valtio/wiki/How-valtio-works |
+1 to the wiki page and for diagrams on how proxies update. It'd also be great to to get some comparisons with other libraries like jotai (comparing how the internals are implemented) |
@akutruff 's comment in #155 (comment) :
I think we should add this in the wiki page, but let me try describing how snapshot creation is optimized in valtio. const state = proxy({ a: { aa: 1 }, b: { bb: 2 } })
const snap1 = snapshot(state)
console.log(snap1) // ---> { a: { aa: 1 }, b: { bb: 2 } }
++state.a.aa
const snap2 = snapshot(state)
console.log(snap2) // ---> { a: { aa: 2 }, b: { bb: 2 } }
snap1.b === snap2.b // this is `true`, it doesn't create a new snapshot because no properties are changed. |
@dai-shi: is it possible to add a |
I'm not sure what you mean by |
Updated: https://github.com/pmndrs/valtio/wiki/How-valtio-works |
To let you know, search engines are unable to index github wiki's, so all the content in the wiki is not available to be searched |
Ah, thanks for the note. that is a drawback, compared to putting the content in the repo. |
Code comments and a high level design doc would be really appreciated. I'm trying to grock what's going on and there's quite a bit of code in each function / it's unclear what's happening in each layer.
For example:
valtio/src/react.ts
Line 126 in bfbf0c5
My eyes are crossing trying to drill through this even before getting into the vanilla layer.
I'd start with useMutableSource and how it is used. What's the snapshot supposed to be. I know you're emulating the new API in React, but I can't make out what's actually in a snapshot. It's a proxy? When if ever is data copied and at what layer?
The text was updated successfully, but these errors were encountered: