Created
April 4, 2017 12:25
-
-
Save d4rky-pl/4d10c3fd6a26c6fd112f6ce8a78627e5 to your computer and use it in GitHub Desktop.
converter from unified to separated mode in mobx-react-form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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