Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

BabelPlugin for infering store structure. #3

Open
blainekasten opened this issue Apr 20, 2016 · 0 comments
Open

BabelPlugin for infering store structure. #3

blainekasten opened this issue Apr 20, 2016 · 0 comments

Comments

@blainekasten
Copy link
Owner

MVP requires a property of store on Provider. I dream of a day where a Babel Transform can assume all of the store's structure for you so you don't have to map these things. By observing the relationship of components to state, I think it should be inferable.

API for default state?

This is an unknown, but if the state is not needed as a default argument, there has to be a way to set the default state. Initial thoughts are a callback of a sort.

<Provider defaultState={() => { foo: 'bar', x: true }} />

Knowing store shape benefits

If we can probably infer the store shape, we can also then do a propType type thing to make sure updatedState doesn't break the shape. For example:

If we know that state.x is an array, and somebody's action tries to set it to a string, then the store API is broken.

// state.nicknames = ['joe', 'james', 'john'];

// action
updateNickname({nickname}, next) {
  next({nickname: 'jacked up joe'});
});

This should throw an error because the state is inferred to be an array from either some default data, or through introspection of other components.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant