10 lines
216 B
TypeScript
10 lines
216 B
TypeScript
export function once<T>(cb: (...args: T[]) => void) {
|
|
let state = { called: false }
|
|
|
|
return (...args: T[]) => {
|
|
if (state.called) return
|
|
state.called = true
|
|
return cb(...args)
|
|
}
|
|
}
|