From 244d10dc9eafe5b9daf266e3a3880c888e4de540 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Fri, 5 May 2023 16:48:35 +0200 Subject: [skip ci] Fix handleComponentFailed spam --- src/utils/onlyOnce.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/utils/onlyOnce.ts (limited to 'src/utils/onlyOnce.ts') 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 . +*/ + +export function onlyOnce(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; +} -- cgit