[RFC] New context provider for useTres state #321
Replies: 7 comments 3 replies
-
Update: POC for state done here https://github.com/Tresjs/state-poc Result: is working as expected (I simulate an async write on the state on the core package and the playground watchers react to it) |
Beta Was this translation helpful? Give feedback.
-
I like the PoC. I would call the composables differently though. The way Markus did name his here is quite good in my opinion. The equivalents in our case would be @alvarosabu What would you think about passing the things which are initially known (like the canvas and the scene for example) to |
Beta Was this translation helpful? Give feedback.
-
Next step: Design of stateWe should answer following questions regarding We can get some inspiration from https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/core/store.ts but i will like to focus on which properties we need to make the ecosystem work |
Beta Was this translation helpful? Give feedback.
-
@alvarosabu @JaimeTorrealba Thank you for the great meeting yesterday. I think we found a good structure for the context. Here are our findings concerning the stuff we want to have in the context.
We were not quite sure if the container around the main canvas element is required or not. We will find out though |
Beta Was this translation helpful? Give feedback.
-
Thanks, @Tinoooo, I will add: Controls property will be moved to useCientos() |
Beta Was this translation helpful? Give feedback.
-
Update, complete refactor for #331 is now available on https://github.com/Tresjs/tres/releases/tag/2.4.0-next.7 thanks to @Tinoooo for the amazing work. |
Beta Was this translation helpful? Give feedback.
-
Well we can say this is done 💚 |
Beta Was this translation helpful? Give feedback.
-
Summary
This proposal introduces a change in how the core manages and distributes the internal state to the ecosystem.
Refactor this:
To something like this:
The state needs to be able to be injected into the packages of the ecosystem via
provide/inject
API and the subpackage should be able to watch the effects when the state is changed.Motivation
In v2, the core state is a
shallowReactive
object to ensure decent performance on the render of the 3D scene. However, packages that depend on this state like (@Tresjs/cientos or @Tresjs/postprocessing ) need to watch the whole state for changes, meaning that any of the properties could trigger a not desired callback.Having a strongly typed store that can be injected will give more control to the maintainers, selecting what parts of the store can be modified or
readonly
Drawbacks
Adoption strategy
It's not clear yet if this change will affect the end-user or only the plugin authors. For testing purposes, the code of the core will be released on a
next channel
in npm for testing in the ecosystemThe following tasks will need:
Beta Was this translation helpful? Give feedback.
All reactions