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
const propSelector = (prop, ctx) => (typeof prop === 'function' ? prop(ctx) : (prop ?? '')); | |
const tinyTpl = (parts, ...props) => | |
(ctx) => parts.map((v, i) => v.concat(propSelector(props[i], ctx))).join(''); | |
const get = (prop) => (ctx) => ctx[prop]; | |
const template = tinyTpl`hello ${get('name')} ${'yay'}!` | |
console.log(template({ name: 'Luca' })) |
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
// https://jsbin.com/fumuwiqegu/edit?js,console | |
/* | |
Create a memo higher order function that works with any number and type of params. | |
This solution uses hashmaps to achieve fast performance. | |
cache = Map { | |
[[ValueSymbol]] => value, | |
arg1 => Map { |
OlderNewer