29 Feb 2020
—
JavaScript,
Design Pattern,
Performance
Using a generator function’s yield
we can segment a long running process into small chunks that fit the Idle Until Urgent pattern.
const promise = new IdlePromise(function* (resolve, reject) {
chunkA()
yield
chunkB()
yield
chunkC()
resolve()
})
Read more
02 Dec 2019
—
JavaScript,
Methods
You can customize all the ways objects are manipulated with Proxy
, and still use the built in object prototype methods with Reflect
.
const proxy = new Proxy(object, Reflect)
Read more
01 Dec 2019
—
JavaScript,
Methods
Proxy
allows you to intercept all object prototype methods.
new Proxy(object, {
get: (obj, key) => { return 42 }
}) // the answer to everything is 42
Read more
30 Nov 2019
—
JavaScript
Just a simple way to conditionnaly add a key-value pair at object declaration.
const obj = {
...(flag && {key: value})
}
Read more
29 Nov 2019
—
JavaScript,
Design Pattern,
Closures,
Good practices
When only a small portion of your function needs to change, try to encapsulate it one level of abstraction above.
const getNavTo = index => () => {
navigateTo(index)
}
document.querySelectorAll('.tab').forEach(($el, index) => {
$el.addEventListener('click', getNavTo(index))
})
Read more