From 56ec91ff275e9ecbc27371cf638531b742bcca6b Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 16:30:58 +0200 Subject: [PATCH] update util.once to add a handler for multiple callbacks --- www/common/common-util.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/www/common/common-util.js b/www/common/common-util.js index 580b9f539..ba70b0ceb 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -222,13 +222,14 @@ return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); }; + Util.noop = function () {}; + /* for wrapping async functions such that they can only be called once */ - Util.once = function (f) { - var called; + Util.once = function (f, g) { return function () { - if (called) { return; } - called = true; + if (!f) { return; } f.apply(this, Array.prototype.slice.call(arguments)); + f = g; }; };