From e33077b752b7882d952de2b2a51170f3f31b440b Mon Sep 17 00:00:00 2001 From: apanizo Date: Mon, 16 Apr 2018 14:44:09 +0200 Subject: [PATCH] WA-230 moving ensureOnce util function to singleton.js --- src/utils/singleton.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/utils/singleton.js 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 + } +}