2019-10-24 19:03:10 -07:00
|
|
|
// We name this __thunk__ so that we can tell terser that it's a pure function, without possibly
|
|
|
|
// affecting third-party libraries that may also be using a function called "thunk".
|
|
|
|
export function __thunk__ (func) {
|
2018-12-05 21:34:30 -08:00
|
|
|
let cached
|
|
|
|
let runOnce
|
|
|
|
return () => {
|
|
|
|
if (!runOnce) {
|
|
|
|
cached = func()
|
|
|
|
runOnce = true
|
|
|
|
}
|
|
|
|
return cached
|
|
|
|
}
|
|
|
|
}
|