Skip to content

Instantly share code, notes, and snippets.

@copperwall
Created March 30, 2019 17:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Form.getProps = form => Object.assign({},
...Object.entries(form)
.filter(([formPropKey, formProp]) => formPropKey !== 'fields')
.map(([formPropKey, formProp]) => ({
[formPropKey]: formProp instanceof Function ? formProp(form) : formProp,
})),
{
fields: Object.assign({}, ...Object.entries(form.fields).map(([fieldKey, field]) => ({
[fieldKey]: Object.assign({}, ...Object.entries(field).map(([fieldPropKey, fieldProp]) => ({
[fieldPropKey]: fieldProp instanceof Function ? fieldProp(form, fieldKey) : fieldProp,
}))),
}))),
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment