From 7fd38f4933cb57e996ee4b31bce38f03c4f37840 Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Tue, 21 Jun 2022 15:01:03 -0500 Subject: [PATCH] DEV: Remove `isLegacyEmber` (#17181) --- .../discourse-common/addon/lib/debounce.js | 8 +- .../app/initializers/inject-objects.js | 78 +++++++++---------- .../discourse/app/lib/d-popover.js | 13 +--- .../app/pre-initializers/map-routes.js | 15 ---- .../discourse/app/services/presence.js | 9 +-- .../discourse/tests/setup-tests.js | 28 +------ 6 files changed, 46 insertions(+), 105 deletions(-) diff --git a/app/assets/javascripts/discourse-common/addon/lib/debounce.js b/app/assets/javascripts/discourse-common/addon/lib/debounce.js index dcd2693b78c..cfd54b32d6f 100644 --- a/app/assets/javascripts/discourse-common/addon/lib/debounce.js +++ b/app/assets/javascripts/discourse-common/addon/lib/debounce.js @@ -1,5 +1,5 @@ -import { debounce, next, run } from "@ember/runloop"; -import { isLegacyEmber, isTesting } from "discourse-common/config/environment"; +import { debounce, next } from "@ember/runloop"; +import { isTesting } from "discourse-common/config/environment"; /** Debounce a Javascript function. This means if it's called many times in a time limit it @@ -7,13 +7,11 @@ import { isLegacyEmber, isTesting } from "discourse-common/config/environment"; Original function will be called with the context and arguments from the last call made. **/ -let testingFunc = isLegacyEmber() ? run : next; - export default function () { if (isTesting()) { // Don't include the time argument (in ms) let args = [].slice.call(arguments, 0, -1); - return testingFunc.apply(void 0, args); + return next.apply(void 0, args); } else { return debounce(...arguments); } diff --git a/app/assets/javascripts/discourse/app/initializers/inject-objects.js b/app/assets/javascripts/discourse/app/initializers/inject-objects.js index 6f3c229da6a..18fc431d3f6 100644 --- a/app/assets/javascripts/discourse/app/initializers/inject-objects.js +++ b/app/assets/javascripts/discourse/app/initializers/inject-objects.js @@ -1,54 +1,50 @@ import { setDefaultOwner } from "discourse-common/lib/get-owner"; -import { isLegacyEmber } from "discourse-common/config/environment"; import User from "discourse/models/user"; import Site from "discourse/models/site"; import deprecated from "discourse-common/lib/deprecated"; export default { name: "inject-objects", - after: isLegacyEmber() ? null : "export-application-global", + after: "export-application-global", initialize(container, app) { // This is required for Ember CLI tests to work setDefaultOwner(app.__container__); - // Backwards compatibility for Discourse.SiteSettings and Discourse.User - if (!isLegacyEmber()) { - Object.defineProperty(app, "SiteSettings", { - get() { - deprecated( - `use injected siteSettings instead of Discourse.SiteSettings`, - { - since: "2.8", - dropFrom: "2.9", - } - ); - return container.lookup("site-settings:main"); - }, - }); - Object.defineProperty(app, "User", { - get() { - deprecated( - `import discourse/models/user instead of using Discourse.User`, - { - since: "2.8", - dropFrom: "2.9", - } - ); - return User; - }, - }); - Object.defineProperty(app, "Site", { - get() { - deprecated( - `import discourse/models/site instead of using Discourse.Site`, - { - since: "2.8", - dropFrom: "2.9", - } - ); - return Site; - }, - }); - } + Object.defineProperty(app, "SiteSettings", { + get() { + deprecated( + `use injected siteSettings instead of Discourse.SiteSettings`, + { + since: "2.8", + dropFrom: "2.9", + } + ); + return container.lookup("site-settings:main"); + }, + }); + Object.defineProperty(app, "User", { + get() { + deprecated( + `import discourse/models/user instead of using Discourse.User`, + { + since: "2.8", + dropFrom: "2.9", + } + ); + return User; + }, + }); + Object.defineProperty(app, "Site", { + get() { + deprecated( + `import discourse/models/site instead of using Discourse.Site`, + { + since: "2.8", + dropFrom: "2.9", + } + ); + return Site; + }, + }); }, }; diff --git a/app/assets/javascripts/discourse/app/lib/d-popover.js b/app/assets/javascripts/discourse/app/lib/d-popover.js index 9c943d979a1..f5d5e131b54 100644 --- a/app/assets/javascripts/discourse/app/lib/d-popover.js +++ b/app/assets/javascripts/discourse/app/lib/d-popover.js @@ -1,5 +1,3 @@ -import { isLegacyEmber } from "discourse-common/config/environment"; -import { begin, end } from "@ember/runloop"; import tippy from "tippy.js"; import { iconHTML } from "discourse-common/lib/icon-library"; @@ -39,14 +37,6 @@ export function showPopover(event, options = {}) { ? event.target._tippy : setup(event.target, options); - // hangs on legacy ember - if (!isLegacyEmber) { - begin(); - instance.popper.addEventListener("transitionend", end, { - once: true, - }); - } - if (instance.state.isShown) { instance.hide(); } else { @@ -72,8 +62,7 @@ export default function setup(target, options) { options ); - // legacy support - delete tippyOptions.textContent; + // legacy support delete tippyOptions.textContent; delete tippyOptions.htmlContent; return tippy(target, tippyOptions); diff --git a/app/assets/javascripts/discourse/app/pre-initializers/map-routes.js b/app/assets/javascripts/discourse/app/pre-initializers/map-routes.js index 19933c14804..27b1196a8ca 100644 --- a/app/assets/javascripts/discourse/app/pre-initializers/map-routes.js +++ b/app/assets/javascripts/discourse/app/pre-initializers/map-routes.js @@ -1,9 +1,5 @@ -import Application from "@ember/application"; -import { isLegacyEmber } from "discourse-common/config/environment"; import { registerRouter, teardownRouter } from "discourse/mapping-router"; -let originalBuildInstance; - export default { name: "map-routes", after: "inject-discourse-objects", @@ -12,17 +8,6 @@ export default { let routerClass = registerRouter(app); container.registry.register("router:main", routerClass); this.routerClass = routerClass; - - if (isLegacyEmber()) { - // HACK to fix: https://github.com/emberjs/ember.js/issues/10310 - originalBuildInstance = - originalBuildInstance || Application.prototype.buildInstance; - - Application.prototype.buildInstance = function () { - this.buildRegistry(); - return originalBuildInstance.apply(this); - }; - } }, teardown() { diff --git a/app/assets/javascripts/discourse/app/services/presence.js b/app/assets/javascripts/discourse/app/services/presence.js index 98fa6445f25..0219142a016 100644 --- a/app/assets/javascripts/discourse/app/services/presence.js +++ b/app/assets/javascripts/discourse/app/services/presence.js @@ -12,7 +12,6 @@ import { } from "@ember/runloop"; import Session from "discourse/models/session"; import { Promise } from "rsvp"; -import { isLegacyEmber, isTesting } from "discourse-common/config/environment"; import User from "discourse/models/user"; import userPresent, { onPresenceChange, @@ -20,6 +19,7 @@ import userPresent, { } from "discourse/lib/user-presence"; import { bind } from "discourse-common/utils/decorators"; import Evented from "@ember/object/evented"; +import { isTesting } from "discourse-common/config/environment"; const PRESENCE_INTERVAL_S = 30; const PRESENCE_DEBOUNCE_MS = isTesting() ? 0 : 500; @@ -549,13 +549,6 @@ export default class PresenceService extends Service { } }); } catch (e) { - if (e.jqXHR?.status === 403 && isTesting() && isLegacyEmber()) { - // Legacy testing environment will remove the User.current() value before disposing of controllers/components. - // Presence often involves making HTTP calls during disposal of components, so this can cause issues. - // Modern Ember-CLI environment does not require this hack - return; - } - // Put the failed events back in the queue for next time this._queuedEvents.unshift(...queue); if (e.jqXHR?.status === 429) { diff --git a/app/assets/javascripts/discourse/tests/setup-tests.js b/app/assets/javascripts/discourse/tests/setup-tests.js index 94ed942a69e..d441da9f1f6 100644 --- a/app/assets/javascripts/discourse/tests/setup-tests.js +++ b/app/assets/javascripts/discourse/tests/setup-tests.js @@ -34,9 +34,9 @@ import { flushMap } from "discourse/services/store"; import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects"; import sinon from "sinon"; import { run } from "@ember/runloop"; -import { isLegacyEmber } from "discourse-common/config/environment"; import { disableCloaking } from "discourse/widgets/post-stream"; import { clearState as clearPresenceState } from "discourse/tests/helpers/presence-pretender"; +import { addModuleExcludeMatcher } from "ember-cli-test-loader/test-support/index"; const Plugin = $.fn.modal; const Modal = Plugin.Constructor; @@ -298,19 +298,11 @@ function setupTestsCommon(application, container, config) { createHelperContext({ get siteSettings() { - if (isLegacyEmber() && container.isDestroyed) { - return settings; - } else { - return container.lookup("site-settings:main"); - } + return container.lookup("site-settings:main"); }, capabilities: {}, get site() { - if (isLegacyEmber() && container.isDestroyed) { - return Site.current(); - } else { - return container.lookup("site:main") || Site.current(); - } + return container.lookup("site:main") || Site.current(); }, registry: app.__registry__, }); @@ -389,19 +381,7 @@ function setupTestsCommon(application, container, config) { return true; }; - if (isLegacyEmber()) { - Object.keys(requirejs.entries).forEach(function (entry) { - if (shouldLoadModule(entry)) { - require(entry, null, null, true); - } - }); - } else { - // Ember CLI - const emberCliTestLoader = require("ember-cli-test-loader/test-support/index"); - emberCliTestLoader.addModuleExcludeMatcher( - (name) => !shouldLoadModule(name) - ); - } + addModuleExcludeMatcher((name) => !shouldLoadModule(name)); // forces 0 as duration for all jquery animations // eslint-disable-next-line no-undef