Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Autobind state props. to component props #5

Open
SamLebarbare opened this issue Mar 22, 2016 · 5 comments
Open

Autobind state props. to component props #5

SamLebarbare opened this issue Mar 22, 2016 · 5 comments

Comments

@SamLebarbare
Copy link
Member

SamLebarbare commented Mar 22, 2016

We must fix a convention for state properties and component properties.

Ex:
<Comp errorText={this.read ('errorText')} />

Next we can inject transparently with something like :

<Comp {...state.readall ()} />

@epsitec
Copy link
Member

epsitec commented Mar 23, 2016

It looks like a good idea to reduce useless right-hand to left-hand shuffling when all is needed is forwarding of state properties. But... usually, a field will be stored as a node, with its default being the value, and various additional key/value pairs used to convey additional information.

So should your suggested state.readall () simply iterate all key/value pairs of the state node? What about the default value?

I suppose a discussion (face to face) will be needed to clarify your intent.

@SamLebarbare
Copy link
Member Author

face2face 👍

@epsitec
Copy link
Member

epsitec commented Apr 22, 2016

@SamLebarbare do you still see a need for this?

@SamLebarbare
Copy link
Member Author

Sometimes components need to bind more than one property from a state node.
Ex. in this case, we need a value for glyph and one for text
<RichButton glyph="..." text="..." />

Idealy i need 2 fields (=2 nodes) for this component, because, if the icon change, the component must rerender, and if the text change it's the same battle.

Actually we can't do that with the field property:
<Richbutton field="Info" /> // internally RichButton must use value.. but on wich property? text ?

So we are faced to make limitative choices on which property must be mapped behing the value received by the node.

On simple component like <Text> or <Label> that seems ok, but a <RichButton loose some power with only one field value mapped to text.

I conclude we can't do multi-mapping with current API and components must expose only one dynamic property (using the value of the node).

What about other keys/values on node ? they can't trigger a rerender if node generation is not updated ?

@epsitec
Copy link
Member

epsitec commented Apr 28, 2016

@SamLebarbare - Nothing prevents you from implementing <RichButton field="Info"/> in project Lydia, which will be
converted into <RichButton {...this.link ('Info')} /> and fed into a viewer.

The <RichButton> component could then do something like this:

render () {
  const {state} = this.props;
  const glyph = this.props.glyph || state.get ('icon');
  const text  = this.props.text || state.get ('value');
  ...
}

However, on the current implementation, there is no support for producing anything else than
just plain values based on form fields. Event field state is currently not available through the form instance in the C# presentation layer.

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

No branches or pull requests

2 participants