semaphore/routes/_utils/once.js

9 lines
229 B
JavaScript

// svelte helper to add a .once() method similar to .on, but only fires once
export function once (eventName, callback) {
let listener = this.on(eventName, eventValue => {
listener.cancel()
callback(eventValue)
})
}