Skip to content

Instantly share code, notes, and snippets.

View LucaColonnello's full-sized avatar
👋
Come say hello on Twitter!

Luca Colonnello LucaColonnello

👋
Come say hello on Twitter!
View GitHub Profile
@LucaColonnello
LucaColonnello / tinyTpl.js
Created May 25, 2021 09:24
Tiny template - using ES6 native tiny template implementation
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' }))
@LucaColonnello
LucaColonnello / memo.js
Last active March 17, 2022 10:27
Memo higher order function that works with any number and type of params.
// 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 {