Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const defineComponent = async (component, state, context) => {
// TODO BRN: If we ever need to retrigger define (redefine) hydrating state here may be an issue
if (!isComponent(component)) {
throw new TypeError(
`defineComponent expected component parameter to be a component. Instead received ${component}`
)
}
component = hydrateComponent(component, state, context)
if (isFunction(component.define)) {
let children = await or(component.define(context), {})
children = filter(isComponent, map(resolve, children))
if (isObject(children)) {
forEach((child) => {
// TODO BRN: Look for children that already have parents. If this is the case then someone has returned a child from define that was defined by another component (possibly passed along as a variable)
child.parent = component
// child = setKey(appendKey(getKey(component), kdx), child)
}, children)
} else {
throw new Error(
`define() method must return either an object or an array. Instead received ${children} from ${component}.`
)
}
component.children = await map(
async (child, key) => defineComponent(child, get(['children', key], state), context),
children
)
}
return component
const visitVariables = (value, visited) => {
value = resolve(value)
if (value && !visited.has(value)) {
if (isArray(value)) {
visited.add(value)
forEachIndexed((aValue, index) => (value[index] = visitVariables(aValue, visited)), value)
visited.delete(value)
} else if (isObject(value)) {
visited.add(value)
forEachObjIndexed((oValue, key) => {
if (key !== 'children' && key !== 'inputTypes') {
value[key] = visitVariables(oValue, visited)
}
}, value)
visited.delete(value)
}
}
return value
}
return (accum, value, keys, iteratee, recur) => {
let result = accum
if (isEvaluable(value)) {
visited.add(value)
result = iteratee(result, value, keys)
value = resolve(value)
if (isComponent(value) || !isObject(value)) {
return result
}
}
if (isObject(value) && !visited.has(value)) {
if (isArray(value) || !isNativeObject(value)) {
visited.add(value)
forEach((childValue, childKdx) => {
if (!isComponent(childValue)) {
const newKeys = concat(keys, [childKdx])
result = recur(result, childValue, newKeys, iteratee)
}
}, value)
}
}
return result
}
}
const walkee = (accum, component, keys, iteratee, recur) => {
let result = accum
const children = resolve(component.children)
if (isObject(children)) {
forEach((child, childKdx) => {
const newKeys = concat(keys, [childKdx])
result = recur(result, resolve(child), newKeys, iteratee)
}, children)
}
return iteratee(result, component, keys)
}
forEach((val, key) => {
if (isArray(val)) {
printArray(val, subLog, level + 1)
} else if (isObject(val)) {
log(`${key}:`)
printObj(val, subLog, level + 1)
} else {
log(`${key}: ${val}`)
}
}, obj)
}
return (accum, value, keys, iteratee, recur) => {
let result = accum
if (isEvaluable(value)) {
visited.add(value)
result = iteratee(result, value, keys)
value = resolve(value)
if (isComponent(value) || !isObject(value)) {
return result
}
}
if (isObject(value) && !visited.has(value)) {
if (isArray(value) || !isNativeObject(value)) {
visited.add(value)
forEach((childValue, childKdx) => {
if (!isComponent(childValue)) {
const newKeys = concat(keys, [childKdx])
result = recur(result, childValue, newKeys, iteratee)
}
}, value)
}
}
return result
}
return (accum, value, keys, iteratee, recur) => {
let result = accum
if (isObject(value) && !visited.has(value)) {
if (isArray(value) || (!isNativeObject(value) && !isVariable(value))) {
visited.add(value)
forEach((childValue, childKdx) => {
const newKeys = concat(keys, [childKdx])
if (isComponent(childValue)) {
visited.add(childValue)
result = iteratee(result, childValue, newKeys)
} else {
result = recur(result, childValue, newKeys, iteratee)
}
}, value)
}
}
return result
}
}
return (accum, value, keys, iteratee, recur) => {
let result = accum
if (isObject(value) && !visited.has(value)) {
if (isVariable(value)) {
visited.add(value)
result = iteratee(result, value, keys)
} else if (isArray(value) || !isNativeObject(value)) {
visited.add(value)
forEach((childValue, childKdx) => {
if (!isComponent(childValue)) {
const newKeys = concat(keys, [childKdx])
result = recur(result, childValue, newKeys, iteratee)
}
}, value)
}
}
return result
}
}
const isTypeConstruct = (value) =>
isString(getProp('type', value)) && isObject(getProp('inputs', value))
const reduceWalkee = (accum, component, keys, iteratee, recur) => {
let result = iteratee(accum, component, keys)
const children = resolve(component.children)
if (isObject(children)) {
forEach((child, childKdx) => {
const newKeys = concat(keys, [childKdx])
result = recur(result, resolve(child), newKeys, iteratee)
}, children)
}
return result
}