Conversation
| initStore = (key, Store, fromContainer) => { | ||
| const { initialState, actions } = Store; | ||
|
|
||
| if (Store.containedBy && !fromContainer) { |
There was a problem hiding this comment.
So it's not checking that container is the one indicated by containedBy, allowing any other container to be present.
Question - how I can disable or satisfy this condition in tests, where isolation might be not as required, or where I don't want to fix too many things at once?
There was a problem hiding this comment.
allowing any other container to be present
Only the ones targeting the same type! The store creation is triggered by a matching container, not any container.
how I can disable or satisfy this condition in tests
There are 2 patterns devs can use in tests:
- use the
containedBycontainer directly - use a new
createContainer(Store), which also allows to overrideonInit/onUpdate
The latter might be better for storybooks/tests, but as long as there is a container that captures the store state somewhere in the tree, it will work without complaining.
This should also help pushing teams writing tests without accidentally leaking to global when containedBy is used.
The new Store API,
containedBy, allows us to signal whenever a store is being used in global context but the creator intended it to be used behind a container.This is especially helpful to detect leaking stores, where the UI might still work but the data accidentally will be retained in the global space.
Closes #190