aboutsummaryrefslogtreecommitdiff
path: root/src/utils/onlyOnce.ts
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2023-05-05 16:48:35 +0200
committerVendicated <vendicated@riseup.net>2023-05-05 16:57:58 +0200
commit244d10dc9eafe5b9daf266e3a3880c888e4de540 (patch)
tree7be248df0997a861637efdeae209d7c578fac160 /src/utils/onlyOnce.ts
parentc25bc0ff4b597131ed223fd5c1a8cf75ac5282e3 (diff)
downloadVencord-244d10dc9eafe5b9daf266e3a3880c888e4de540.tar.gz
Vencord-244d10dc9eafe5b9daf266e3a3880c888e4de540.tar.bz2
Vencord-244d10dc9eafe5b9daf266e3a3880c888e4de540.zip
[skip ci] Fix handleComponentFailed spam
Diffstat (limited to 'src/utils/onlyOnce.ts')
-rw-r--r--src/utils/onlyOnce.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utils/onlyOnce.ts b/src/utils/onlyOnce.ts
new file mode 100644
index 0000000..f5cb8c9
--- /dev/null
+++ b/src/utils/onlyOnce.ts
@@ -0,0 +1,29 @@
+/*
+ * Vencord, a modification for Discord's desktop app
+ * Copyright (c) 2023 Vendicated and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+export function onlyOnce<F extends Function>(f: F): F {
+ let called = false;
+ let result: any;
+ return function onlyOnceWrapper(this: unknown) {
+ if (called) return result;
+
+ called = true;
+
+ return (result = f.apply(this, arguments));
+ } as unknown as F;
+}