diff --git a/src/utils/singleton.js b/src/utils/singleton.js new file mode 100644 index 00000000..5517a770 --- /dev/null +++ b/src/utils/singleton.js @@ -0,0 +1,14 @@ +// @flow +export const ensureOnce = (fn: Function): Function => { + let executed = false + let response + + return (...args) => { + if (executed) { return response } + + executed = true + response = fn(args) + + return response + } +}