DEV: Remove `isLegacyEmber` (#17181)
This commit is contained in:
parent
41028a84ef
commit
7fd38f4933
|
@ -1,5 +1,5 @@
|
||||||
import { debounce, next, run } from "@ember/runloop";
|
import { debounce, next } from "@ember/runloop";
|
||||||
import { isLegacyEmber, isTesting } from "discourse-common/config/environment";
|
import { isTesting } from "discourse-common/config/environment";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Debounce a Javascript function. This means if it's called many times in a time limit it
|
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.
|
Original function will be called with the context and arguments from the last call made.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
let testingFunc = isLegacyEmber() ? run : next;
|
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
if (isTesting()) {
|
if (isTesting()) {
|
||||||
// Don't include the time argument (in ms)
|
// Don't include the time argument (in ms)
|
||||||
let args = [].slice.call(arguments, 0, -1);
|
let args = [].slice.call(arguments, 0, -1);
|
||||||
return testingFunc.apply(void 0, args);
|
return next.apply(void 0, args);
|
||||||
} else {
|
} else {
|
||||||
return debounce(...arguments);
|
return debounce(...arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,50 @@
|
||||||
import { setDefaultOwner } from "discourse-common/lib/get-owner";
|
import { setDefaultOwner } from "discourse-common/lib/get-owner";
|
||||||
import { isLegacyEmber } from "discourse-common/config/environment";
|
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
import deprecated from "discourse-common/lib/deprecated";
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "inject-objects",
|
name: "inject-objects",
|
||||||
after: isLegacyEmber() ? null : "export-application-global",
|
after: "export-application-global",
|
||||||
initialize(container, app) {
|
initialize(container, app) {
|
||||||
// This is required for Ember CLI tests to work
|
// This is required for Ember CLI tests to work
|
||||||
setDefaultOwner(app.__container__);
|
setDefaultOwner(app.__container__);
|
||||||
|
|
||||||
// Backwards compatibility for Discourse.SiteSettings and Discourse.User
|
Object.defineProperty(app, "SiteSettings", {
|
||||||
if (!isLegacyEmber()) {
|
get() {
|
||||||
Object.defineProperty(app, "SiteSettings", {
|
deprecated(
|
||||||
get() {
|
`use injected siteSettings instead of Discourse.SiteSettings`,
|
||||||
deprecated(
|
{
|
||||||
`use injected siteSettings instead of Discourse.SiteSettings`,
|
since: "2.8",
|
||||||
{
|
dropFrom: "2.9",
|
||||||
since: "2.8",
|
}
|
||||||
dropFrom: "2.9",
|
);
|
||||||
}
|
return container.lookup("site-settings:main");
|
||||||
);
|
},
|
||||||
return container.lookup("site-settings:main");
|
});
|
||||||
},
|
Object.defineProperty(app, "User", {
|
||||||
});
|
get() {
|
||||||
Object.defineProperty(app, "User", {
|
deprecated(
|
||||||
get() {
|
`import discourse/models/user instead of using Discourse.User`,
|
||||||
deprecated(
|
{
|
||||||
`import discourse/models/user instead of using Discourse.User`,
|
since: "2.8",
|
||||||
{
|
dropFrom: "2.9",
|
||||||
since: "2.8",
|
}
|
||||||
dropFrom: "2.9",
|
);
|
||||||
}
|
return User;
|
||||||
);
|
},
|
||||||
return User;
|
});
|
||||||
},
|
Object.defineProperty(app, "Site", {
|
||||||
});
|
get() {
|
||||||
Object.defineProperty(app, "Site", {
|
deprecated(
|
||||||
get() {
|
`import discourse/models/site instead of using Discourse.Site`,
|
||||||
deprecated(
|
{
|
||||||
`import discourse/models/site instead of using Discourse.Site`,
|
since: "2.8",
|
||||||
{
|
dropFrom: "2.9",
|
||||||
since: "2.8",
|
}
|
||||||
dropFrom: "2.9",
|
);
|
||||||
}
|
return Site;
|
||||||
);
|
},
|
||||||
return Site;
|
});
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import { isLegacyEmber } from "discourse-common/config/environment";
|
|
||||||
import { begin, end } from "@ember/runloop";
|
|
||||||
import tippy from "tippy.js";
|
import tippy from "tippy.js";
|
||||||
import { iconHTML } from "discourse-common/lib/icon-library";
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
||||||
|
|
||||||
|
@ -39,14 +37,6 @@ export function showPopover(event, options = {}) {
|
||||||
? event.target._tippy
|
? event.target._tippy
|
||||||
: setup(event.target, options);
|
: setup(event.target, options);
|
||||||
|
|
||||||
// hangs on legacy ember
|
|
||||||
if (!isLegacyEmber) {
|
|
||||||
begin();
|
|
||||||
instance.popper.addEventListener("transitionend", end, {
|
|
||||||
once: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instance.state.isShown) {
|
if (instance.state.isShown) {
|
||||||
instance.hide();
|
instance.hide();
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,8 +62,7 @@ export default function setup(target, options) {
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
// legacy support
|
// legacy support delete tippyOptions.textContent;
|
||||||
delete tippyOptions.textContent;
|
|
||||||
delete tippyOptions.htmlContent;
|
delete tippyOptions.htmlContent;
|
||||||
|
|
||||||
return tippy(target, tippyOptions);
|
return tippy(target, tippyOptions);
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import Application from "@ember/application";
|
|
||||||
import { isLegacyEmber } from "discourse-common/config/environment";
|
|
||||||
import { registerRouter, teardownRouter } from "discourse/mapping-router";
|
import { registerRouter, teardownRouter } from "discourse/mapping-router";
|
||||||
|
|
||||||
let originalBuildInstance;
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "map-routes",
|
name: "map-routes",
|
||||||
after: "inject-discourse-objects",
|
after: "inject-discourse-objects",
|
||||||
|
@ -12,17 +8,6 @@ export default {
|
||||||
let routerClass = registerRouter(app);
|
let routerClass = registerRouter(app);
|
||||||
container.registry.register("router:main", routerClass);
|
container.registry.register("router:main", routerClass);
|
||||||
this.routerClass = 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() {
|
teardown() {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
} from "@ember/runloop";
|
} from "@ember/runloop";
|
||||||
import Session from "discourse/models/session";
|
import Session from "discourse/models/session";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import { isLegacyEmber, isTesting } from "discourse-common/config/environment";
|
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import userPresent, {
|
import userPresent, {
|
||||||
onPresenceChange,
|
onPresenceChange,
|
||||||
|
@ -20,6 +19,7 @@ import userPresent, {
|
||||||
} from "discourse/lib/user-presence";
|
} from "discourse/lib/user-presence";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
import Evented from "@ember/object/evented";
|
import Evented from "@ember/object/evented";
|
||||||
|
import { isTesting } from "discourse-common/config/environment";
|
||||||
|
|
||||||
const PRESENCE_INTERVAL_S = 30;
|
const PRESENCE_INTERVAL_S = 30;
|
||||||
const PRESENCE_DEBOUNCE_MS = isTesting() ? 0 : 500;
|
const PRESENCE_DEBOUNCE_MS = isTesting() ? 0 : 500;
|
||||||
|
@ -549,13 +549,6 @@ export default class PresenceService extends Service {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} 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
|
// Put the failed events back in the queue for next time
|
||||||
this._queuedEvents.unshift(...queue);
|
this._queuedEvents.unshift(...queue);
|
||||||
if (e.jqXHR?.status === 429) {
|
if (e.jqXHR?.status === 429) {
|
||||||
|
|
|
@ -34,9 +34,9 @@ import { flushMap } from "discourse/services/store";
|
||||||
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
|
import { registerObjects } from "discourse/pre-initializers/inject-discourse-objects";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
import { run } from "@ember/runloop";
|
import { run } from "@ember/runloop";
|
||||||
import { isLegacyEmber } from "discourse-common/config/environment";
|
|
||||||
import { disableCloaking } from "discourse/widgets/post-stream";
|
import { disableCloaking } from "discourse/widgets/post-stream";
|
||||||
import { clearState as clearPresenceState } from "discourse/tests/helpers/presence-pretender";
|
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 Plugin = $.fn.modal;
|
||||||
const Modal = Plugin.Constructor;
|
const Modal = Plugin.Constructor;
|
||||||
|
@ -298,19 +298,11 @@ function setupTestsCommon(application, container, config) {
|
||||||
|
|
||||||
createHelperContext({
|
createHelperContext({
|
||||||
get siteSettings() {
|
get siteSettings() {
|
||||||
if (isLegacyEmber() && container.isDestroyed) {
|
return container.lookup("site-settings:main");
|
||||||
return settings;
|
|
||||||
} else {
|
|
||||||
return container.lookup("site-settings:main");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
capabilities: {},
|
capabilities: {},
|
||||||
get site() {
|
get site() {
|
||||||
if (isLegacyEmber() && container.isDestroyed) {
|
return container.lookup("site:main") || Site.current();
|
||||||
return Site.current();
|
|
||||||
} else {
|
|
||||||
return container.lookup("site:main") || Site.current();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
registry: app.__registry__,
|
registry: app.__registry__,
|
||||||
});
|
});
|
||||||
|
@ -389,19 +381,7 @@ function setupTestsCommon(application, container, config) {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isLegacyEmber()) {
|
addModuleExcludeMatcher((name) => !shouldLoadModule(name));
|
||||||
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)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// forces 0 as duration for all jquery animations
|
// forces 0 as duration for all jquery animations
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
|
|
Loading…
Reference in New Issue