Skip to content

Proposal: make exported store name insignificant #43

@gaearon

Description

@gaearon

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions