WA-230 moving ensureOnce util function to singleton.js

This commit is contained in:
apanizo 2018-04-16 14:44:09 +02:00
parent 0094abd4ac
commit e33077b752
1 changed files with 14 additions and 0 deletions

14
src/utils/singleton.js Normal file
View File

@ -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
}
}