This file contains 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 findValue(arr, callback) { | |
for (let index = 0; index < arr.length; index++) { | |
const value = arr[index] | |
if (callback(value)) { | |
return value | |
} | |
} | |
} |
This file contains 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
{ | |
"type": "div", | |
"style": { | |
"height": 300, | |
"fontSize": 14, | |
"fontWeight": "bold", | |
"textAlign": "center" | |
}, | |
"children": [ | |
{ |
This file contains 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
const getBaseStyles = () => ({ baseStyles: { color: '#333' } }) | |
function start(component, { resolvers = {}, displayTimestamp }) { | |
const baseStyles = getBaseStyles() | |
// This is what will be injected in the returned function from the higher order function | |
const context = { baseStyles, displayTimestamp } | |
// This will replace each original resolver and maintain the behavior of the program to behave the same by calling the original resolver inside it | |
const enhancedResolve = makeInjectContext(context) | |
let baseResolvers |
This file contains 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
const getBaseStyles = () => ({ baseStyles: { color: '#333' } }) | |
const baseStyles = getBaseStyles() | |
const injectContext = makeInjectContext({ | |
baseStyles, | |
}) | |
function resolveTimestampInjection(component) { | |
return function ({ displayTimestamp }) { | |
if (displayTimestamp === true) { |
This file contains 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 makeInjectContext(context) { | |
return function (callback) { | |
return function (...args) { | |
let result = callback(...args) | |
if (typeof result === 'function') { | |
// Call it again and inject additional options | |
result = result(context) | |
} | |
return result | |
} |
This file contains 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 } | |
} |
This file contains 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 resolveTimestampInjection(component) { | |
return function ({ displayTimestamp }) { | |
if (displayTimestamp === true) { | |
return { | |
time: new Date(currentDate).toLocaleTimeString(), | |
} | |
} | |
} | |
} |
This file contains 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 } | |
} | |
} |
This file contains 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 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 |
This file contains 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
TypeError: Cannot read property 'children' of undefined |
NewerOlder