Closed albertogasparin closed 1 year ago
Please review @theKashey and @anacierdem 🙏🙏🙏🙏 (hopefully for the last time)
Long story short:
containedBy: CounterContainer
to define a "boundary"createContainer
to create a container in place - for testing, or just because one needs it in place. I've got example with "nested" containers passing "accumulated value" to the children.And I really like how CounterContainer
(from example) can provide props to all nested onInit
functions, no matter how many stores are containedBy inside
Addressed the PR comments and published the reworked docs
Quite solid work, you've invested much more effort than I anticipated, but the outcome is also proportionally better 🎉
Last moment question - should handle behaviour for stores marked to be containedBy
or let's keep this behavior for
containedBy
is "will be containedBy", not "must be containedBy"Why:
If there was something to shout at me earlier - that would save 3 dev days 😉
If there was something to shout at me earlier - that would save 3 dev days
Yes, that will come right after this PR. Didn't wanna overload this one too much because it already has lots of changes 😄
It will be "must be containedBy", and Registry
will validate whenever store has that attribute and throw an async error if that registry is the global one.
Evolution after #196 discussion. We are inverting the Container / Store relationship. Now stores can link to a container via
containedBy
so containers can be shared across stores. Container actions also move to thecreateStore
API (underhandlers
) so there is no need to distinguish between stores in a multi store containment situation. This also makes Containers extremely lightweight, as they can be imported anywhere in the tree without risking importing actions and other Store specific implementations. It will also enable erroring whenever a store should becontainedBy
but it is not (#190).From:
to
We will still support the old API, which now becomes a way to provide overrides in specific situations (eg tests). So if a store has
containedBy
but the subscribers render under a Container that was created explicitly with that store argument, such container will own the state even if it was not the one specified incontainedBy
. The risks of having both styles in a codebase should be minimal, and we can soft push to adopt the new pattern by promoting it by default on the docs and progressively move to it via linting and codemods.