Created
June 9, 2020 15:00
-
-
Save jsmanifest/e0b53eb13f05274c8bc9e3a7f94ff0e6 to your computer and use it in GitHub Desktop.
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
function callResolvers(component, resolvers) { | |
let result | |
for (let index = 0; index < resolvers.length; index++) { | |
const resolver = resolvers[index] | |
const resolved = resolver(component) | |
if (resolved) { | |
result = { ...result, ...resolved } | |
} | |
} | |
return result | |
} | |
function start(component, resolvers = []) { | |
let baseResolvers | |
let styleResolvers | |
// Ensure base resolvers is the correct data type | |
if (Array.isArray(resolvers.base)) baseResolvers = resolvers.base | |
else baseResolvers = [resolvers.base] | |
// Ensure style resolvers is the correct data type | |
if (Array.isArray(resolvers.styles)) styleResolvers = resolvers.styles | |
else styleResolvers = [resolvers.styles] | |
return { | |
...component, | |
...callResolvers(component, baseResolvers), | |
style: { | |
...component.style, | |
...callResolvers(component, styleResolvers)), | |
}, | |
} | |
} | |
const component = { | |
type: 'div', | |
style: { | |
height: 250, | |
fontSize: 14, | |
fontWeight: 'bold', | |
textAlign: 'center', | |
}, | |
children: [ | |
{ | |
type: 'input', | |
inputType: 'email', | |
placeholder: 'Enter your email', | |
style: { | |
border: '1px solid magenta', | |
}, | |
}, | |
], | |
} | |
const result = start(component, { | |
resolvers: { | |
base: [resolveTimestampInjection, resolveChildren], | |
styles: [resolveStyles], | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment