From 349f6e18f380116eac4f08457c864a4eb8428292 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 22 Aug 2022 21:46:30 +0200 Subject: [PATCH] DEV: Correctly clear global exported variables --- .../javascripts/discourse/app/components/topic-title.js | 2 +- .../app/lib/sidebar/custom-community-section-links.js | 4 ++-- .../discourse/app/lib/sidebar/custom-sections.js | 2 +- .../javascripts/discourse/app/lib/user-menu/tab.js | 2 +- .../javascripts/discourse/app/lib/user-presence.js | 2 +- .../javascripts/discourse/app/widgets/post-menu.js | 9 ++++++--- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/topic-title.js b/app/assets/javascripts/discourse/app/components/topic-title.js index 02b4c0211e5..4e46efc8ca6 100644 --- a/app/assets/javascripts/discourse/app/components/topic-title.js +++ b/app/assets/javascripts/discourse/app/components/topic-title.js @@ -9,7 +9,7 @@ export function addTopicTitleDecorator(decorator) { } export function resetTopicTitleDecorators() { - topicTitleDecorators = []; + topicTitleDecorators.length = 0; } export default Component.extend(KeyEnterEscape, { diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/custom-community-section-links.js b/app/assets/javascripts/discourse/app/lib/sidebar/custom-community-section-links.js index 301945fb0f5..64b136d416c 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/custom-community-section-links.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/custom-community-section-links.js @@ -108,6 +108,6 @@ export function addSectionLink(args, secondary) { } export function resetDefaultSectionLinks() { - customSectionLinks = []; - secondaryCustomSectionLinks = []; + customSectionLinks.length = 0; + secondaryCustomSectionLinks.length = 0; } diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/custom-sections.js b/app/assets/javascripts/discourse/app/lib/sidebar/custom-sections.js index 88d594d376b..2284ca57fa2 100644 --- a/app/assets/javascripts/discourse/app/lib/sidebar/custom-sections.js +++ b/app/assets/javascripts/discourse/app/lib/sidebar/custom-sections.js @@ -10,5 +10,5 @@ export function addSidebarSection(func) { } export function resetSidebarSection() { - customSections.splice(0, customSections.length); + customSections.length = 0; } diff --git a/app/assets/javascripts/discourse/app/lib/user-menu/tab.js b/app/assets/javascripts/discourse/app/lib/user-menu/tab.js index 629ff2bff64..b2969624d84 100644 --- a/app/assets/javascripts/discourse/app/lib/user-menu/tab.js +++ b/app/assets/javascripts/discourse/app/lib/user-menu/tab.js @@ -60,5 +60,5 @@ export function registerUserMenuTab(func) { } export function resetUserMenuTabs() { - CUSTOM_TABS_CLASSES.clear(); + CUSTOM_TABS_CLASSES.length = 0; } diff --git a/app/assets/javascripts/discourse/app/lib/user-presence.js b/app/assets/javascripts/discourse/app/lib/user-presence.js index fd062298378..39f257f54d7 100644 --- a/app/assets/javascripts/discourse/app/lib/user-presence.js +++ b/app/assets/javascripts/discourse/app/lib/user-presence.js @@ -120,7 +120,7 @@ export function setTestPresence(value) { } export function clearPresenceCallbacks() { - callbacks.splice(0, callbacks.length); + callbacks.length = 0; } if (!isTesting()) { diff --git a/app/assets/javascripts/discourse/app/widgets/post-menu.js b/app/assets/javascripts/discourse/app/widgets/post-menu.js index 06765614ce7..6c0e520ee2b 100644 --- a/app/assets/javascripts/discourse/app/widgets/post-menu.js +++ b/app/assets/javascripts/discourse/app/widgets/post-menu.js @@ -17,8 +17,8 @@ const LIKE_ACTION = 2; const VIBRATE_DURATION = 5; const _builders = {}; -let _extraButtons = {}; export let apiExtraButtons = {}; +let _extraButtons = {}; let _buttonsToRemove = {}; export function addButton(name, builder) { @@ -26,9 +26,12 @@ export function addButton(name, builder) { } export function resetPostMenuExtraButtons() { - _buttonsToRemove = {}; - apiExtraButtons = {}; + for (const key of Object.keys(apiExtraButtons)) { + delete apiExtraButtons[key]; + } + _extraButtons = {}; + _buttonsToRemove = {}; } export function removeButton(name, callback) {