Generators for idle-until-urgent

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

Proxy & Reflect

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

Proxy use cases

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

Conditional object attribute

Just a simple way to conditionnaly add a key-value pair at object declaration.

const obj = {
    ...(flag && {key: value})
}

Read more

So many closures

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