ylem icon indicating copy to clipboard operation
ylem copied to clipboard

Add mapPropsToStore and mapStoreToProps to connect config object

Open mikedane opened this issue 6 years ago • 0 comments

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.

mikedane avatar Sep 17 '18 19:09 mikedane