Skip to content

Instantly share code, notes, and snippets.

@d4rky-pl
Created April 4, 2017 12:25
Show Gist options
  • Save d4rky-pl/4d10c3fd6a26c6fd112f6ce8a78627e5 to your computer and use it in GitHub Desktop.
Save d4rky-pl/4d10c3fd6a26c6fd112f6ce8a78627e5 to your computer and use it in GitHub Desktop.
converter from unified to separated mode in mobx-react-form
// This script is ugly and simple but it works
// Sharing in case someone else find it useful
window.fieldConverter = (obj) => {
let fields = map(obj, (values, field_name ) => field_name)
let labels = reduce(obj, (acc, values, field_name) => { acc[field_name] = values.label; return acc } ,{})
let rules = reduce(obj, (acc, values, field_name) => { acc[field_name] = values.rules; return acc } ,{})
let defaults = reduce(obj, (acc, values, field_name) => { acc[field_name] = values.default; return acc } ,{})
let types = reduce(obj, (acc, values, field_name) => { acc[field_name] = values.type; return acc } ,{})
let values = reduce(obj, (acc, values, field_name) => { acc[field_name] = values.value; return acc } ,{})
return `const fields = ${JSON.stringify(fields)};
const labels = ${JSON.stringify(labels)};
const rules = ${JSON.stringify(rules)};
const defaults = ${JSON.stringify(defaults)};
const types = ${JSON.stringify(types)};
const values = ${JSON.stringify(values)};
`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment