bitovi / ylem

Add Observable View-Models to React components
https://bitovi.github.io/ylem/
MIT License
42 stars 2 forks source link

Add mapPropsToStore and mapStoreToProps to connect config object #189

Open mikedane opened 6 years ago

mikedane commented 6 years ago

Currently ylem's connect function takes a ViewModel and a Component, but it can also take a second argument which is a config object. Currently this config object only supports one field, deriveUpdates. We want to add support for two additional fields mapPropsToStore and mapStoreToProps.

mapPropsToStore Should allow props to be renamed when they come into the store. Basically the user will pass in a function which maps the props appropriately.

default: mapPropsToStore: (props) => ({ props }) custom example: mapPropsToStore: ({foo, ...rest}) => ({ bar: foo, ...rest })

mapStoreToProps Should allow fields in the store to be renamed when they get passed into the component as props. Basically the user will pass in a function which maps the store fields appropriately.

custom example: mapStoreToProps: ({ props, onFoo }) => ({ ...props, onFoo, })

This one is particularly tricky because react checks to make sure that the props it passes into the component are the props the component received.