-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Description
When specifying Container
or @container
, the name under which the store is exported is insignificant. You just assign it a string key:
@container({
stores: { counter: counterStore }
})
and it appears as counter
.
There is now a single place where it's still significant: the action creator callback form.
export function incrementIfOdd() {
return (dispatch, state) => {
if (state.counterStore % 2 === 0) { // reading from counterStore state here
return;
}
dispatch(increment());
};
}
It's not obvious that it's called counterStore
because of export { default as counterStore } from './counterStore
inside stores/index.js
passed to the @root
.
An alternative is to let state
be ES6 map with Store functions as keys. Then you'd do
import counterStore from './stores/counterStore';
export function incrementIfOdd() {
return (dispatch, state) => {
if (state.get(counterStore) % 2 === 0) { // get state for the store
return;
}
dispatch(increment());
};
}
This code won't break if you rename the export, and also makes the dependency clear.
Thoughts?
Metadata
Metadata
Assignees
Labels
No labels