Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 9, 2020 14:59
Show Gist options
  • Save jsmanifest/ad08270f2a1db770afb1806a1903f59e to your computer and use it in GitHub Desktop.
Save jsmanifest/ad08270f2a1db770afb1806a1903f59e to your computer and use it in GitHub Desktop.
function resolveStyles(component) {
let result = {}
// Restrict it from displaying in a smaller size
if (component.style.height < 300) {
result['height'] = 300
}
if (component.type === 'button') {
// Give all button components a dashed teal border
result['border'] = '1px dashed teal'
}
if (component.type === 'input') {
if (component.inputType === 'email') {
// Uppercase every letter for email inputs
result['textTransform'] = 'uppercase'
}
}
return result
}
function resolveChildren(component) {
if (Array.isArray(component.children)) {
return {
children: component.children.map((child) => {
return resolveStyles(child)
}),
}
}
}
function start(component, resolvers = []) {
return resolvers.reduce((acc, resolve) => {
return resolve(acc)
}, component)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment