Skip to content

Instantly share code, notes, and snippets.

View bluwy's full-sized avatar
♥️
【=◈︿◈=】

Bjorn Lu bluwy

♥️
【=◈︿◈=】
View GitHub Profile
@bluwy
bluwy / get.ts
Created August 7, 2020 07:23
Get the current value of subscribable stores, e.g. Svelte stores
/** Callback to inform of a value updates. */
type Subscriber<T> = (value: T) => void
/** Unsubscribes from value updates. */
type Unsubscriber = () => void
/** A store that can be subscribed */
interface Subscribable<T> {
subscribe: (run: Subscriber<T>) => Unsubscriber
}
@bluwy
bluwy / debounce.js
Created June 18, 2020 11:22
Simple debounce and throttle with proper context binding
function debounce(fn, wait) {
let t
return function () {
clearTimeout(t)
t = setTimeout(() => fn.apply(this, arguments), wait)
}
}