DEV: Replace `topic-tracking-state:main` with `service:topic-tracking-state` (#17802)
This will allow consumers to inject it using `topicTrackingState: service()` in preparation for the removal of implicit injections in Ember 4.0. `topic-tracking-state:main` is still available and will print a deprecation notice. Ideally we would convert topic-tracking-state into a true service, rather than registering a model instance into the registry. However, inter-dependencies between service injections make this very difficult to achieve. We don't want to block Glimmer Component work, so this commit does the minimum for now.
This commit is contained in:
parent
199d9ccb69
commit
c1cdb6bc51
|
@ -83,6 +83,11 @@ const DEPRECATED_MODULES = new Map(
|
|||
since: "2.9.0.beta7",
|
||||
dropFrom: "3.0.0",
|
||||
},
|
||||
"topic-tracking-state:main": {
|
||||
newName: "service:topic-tracking-state",
|
||||
since: "2.9.0.beta7",
|
||||
dropFrom: "3.0.0",
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import GlimmerComponent from "@glimmer/component";
|
||||
import { cached } from "@glimmer/tracking";
|
||||
import { getOwner } from "@ember/application";
|
||||
import { inject as service } from "@ember/service";
|
||||
|
||||
/*
|
||||
|
@ -22,10 +20,5 @@ export default class DiscourseGlimmerComponent extends GlimmerComponent {
|
|||
@service currentUser;
|
||||
@service session;
|
||||
@service site;
|
||||
|
||||
@cached
|
||||
get topicTrackingState() {
|
||||
const applicationInstance = getOwner(this);
|
||||
return applicationInstance.lookup("topic-tracking-state:main");
|
||||
}
|
||||
@service topicTrackingState;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export function autoLoadModules(container, registry) {
|
|||
currentUser: container.lookup("service:current-user"),
|
||||
site: container.lookup("service:site"),
|
||||
session: container.lookup("service:session"),
|
||||
topicTrackingState: container.lookup("topic-tracking-state:main"),
|
||||
topicTrackingState: container.lookup("service:topic-tracking-state"),
|
||||
registry,
|
||||
};
|
||||
setOwner(context, container);
|
||||
|
|
|
@ -46,7 +46,7 @@ export default {
|
|||
currentUser,
|
||||
});
|
||||
|
||||
app.register("topic-tracking-state:main", topicTrackingState, {
|
||||
app.register("service:topic-tracking-state", topicTrackingState, {
|
||||
instantiate: false,
|
||||
});
|
||||
|
||||
|
@ -67,7 +67,7 @@ export default {
|
|||
app.inject(t, "session", "service:session");
|
||||
app.inject(t, "messageBus", "service:message-bus");
|
||||
app.inject(t, "siteSettings", "service:site-settings");
|
||||
app.inject(t, "topicTrackingState", "topic-tracking-state:main");
|
||||
app.inject(t, "topicTrackingState", "service:topic-tracking-state");
|
||||
app.inject(t, "keyValueStore", "service:key-value-store");
|
||||
});
|
||||
|
||||
|
@ -86,7 +86,11 @@ export default {
|
|||
property: "siteSettings",
|
||||
specifier: "service:site-settings",
|
||||
});
|
||||
app.inject("service", "topicTrackingState", "topic-tracking-state:main");
|
||||
injectServiceIntoService({
|
||||
app,
|
||||
property: "topicTrackingState",
|
||||
specifier: "service:topic-tracking-state",
|
||||
});
|
||||
injectServiceIntoService({
|
||||
app,
|
||||
property: "keyValueStore",
|
||||
|
|
|
@ -266,7 +266,9 @@ export default Service.extend({
|
|||
obj.__state = obj[adapter.primaryKey] ? "created" : "new";
|
||||
|
||||
// TODO: Have injections be automatic
|
||||
obj.topicTrackingState = this.register.lookup("topic-tracking-state:main");
|
||||
obj.topicTrackingState = this.register.lookup(
|
||||
"service:topic-tracking-state"
|
||||
);
|
||||
obj.keyValueStore = this.register.lookup("service:key-value-store");
|
||||
|
||||
const klass = this.register.lookupFactory("model:" + type) || RestModel;
|
||||
|
|
|
@ -95,7 +95,7 @@ export default createWidget("hamburger-menu", {
|
|||
},
|
||||
|
||||
lookupCount(type) {
|
||||
const tts = this.register.lookup("topic-tracking-state:main");
|
||||
const tts = this.register.lookup("service:topic-tracking-state");
|
||||
return tts ? tts.lookupCount({ type }) : 0;
|
||||
},
|
||||
|
||||
|
|
|
@ -273,7 +273,7 @@ acceptance("Sidebar - Categories Section", function (needs) {
|
|||
test("new and unread count for categories link", async function (assert) {
|
||||
const { category1, category2 } = setupUserSidebarCategories();
|
||||
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
@ -391,7 +391,7 @@ acceptance("Sidebar - Categories Section", function (needs) {
|
|||
await visit("/");
|
||||
|
||||
const topicTrackingState = this.container.lookup(
|
||||
"topic-tracking-state:main"
|
||||
"service:topic-tracking-state"
|
||||
);
|
||||
|
||||
const initialCallbackCount = Object.keys(
|
||||
|
|
|
@ -492,7 +492,7 @@ acceptance("Sidebar - Community Section", function (needs) {
|
|||
});
|
||||
|
||||
test("new and unread count for everything link", async function (assert) {
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
@ -679,7 +679,7 @@ acceptance("Sidebar - Community Section", function (needs) {
|
|||
const category = categories.find((c) => c.id === 1001);
|
||||
category.set("notification_level", NotificationLevels.TRACKING);
|
||||
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
@ -923,7 +923,7 @@ acceptance("Sidebar - Community Section", function (needs) {
|
|||
await visit("/");
|
||||
|
||||
const topicTrackingState = this.container.lookup(
|
||||
"topic-tracking-state:main"
|
||||
"service:topic-tracking-state"
|
||||
);
|
||||
|
||||
const initialCallbackCount = Object.keys(
|
||||
|
|
|
@ -213,7 +213,7 @@ acceptance("Sidebar - Tags section", function (needs) {
|
|||
});
|
||||
|
||||
test("new and unread count for tag section links", async function (assert) {
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
@ -319,7 +319,7 @@ acceptance("Sidebar - Tags section", function (needs) {
|
|||
await visit("/");
|
||||
|
||||
const topicTrackingState = this.container.lookup(
|
||||
"topic-tracking-state:main"
|
||||
"service:topic-tracking-state"
|
||||
);
|
||||
|
||||
const initialCallbackCount = Object.keys(
|
||||
|
|
|
@ -39,7 +39,7 @@ acceptance("Topic Discovery Tracked", function (needs) {
|
|||
});
|
||||
|
||||
test("navigation items with tracked filter", async function (assert) {
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
@ -104,7 +104,7 @@ acceptance("Topic Discovery Tracked", function (needs) {
|
|||
const category = categories.find((c) => c.id === 1001);
|
||||
category.set("notification_level", NotificationLevels.TRACKING);
|
||||
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
@ -230,7 +230,7 @@ acceptance("Topic Discovery Tracked", function (needs) {
|
|||
});
|
||||
|
||||
test("visit discovery page filtered by tag with tracked filter", async function (assert) {
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
@ -278,7 +278,7 @@ acceptance("Topic Discovery Tracked", function (needs) {
|
|||
const category = categories.at(-1);
|
||||
category.set("notification_level", NotificationLevels.TRACKING);
|
||||
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
this.container.lookup("service:topic-tracking-state").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
highest_post_number: 1,
|
||||
|
|
|
@ -43,17 +43,17 @@ export function setupRenderingTest(hooks) {
|
|||
specifier: "service:current-user",
|
||||
});
|
||||
|
||||
this.owner.unregister("topic-tracking-state:main");
|
||||
this.owner.unregister("service:topic-tracking-state");
|
||||
this.owner.register(
|
||||
"topic-tracking-state:main",
|
||||
"service:topic-tracking-state",
|
||||
TopicTrackingState.create({ currentUser }),
|
||||
{ instantiate: false }
|
||||
);
|
||||
this.owner.inject(
|
||||
"service",
|
||||
"topicTrackingState",
|
||||
"topic-tracking-state:main"
|
||||
);
|
||||
injectServiceIntoService({
|
||||
app: this.owner.application,
|
||||
property: "topicTrackingState",
|
||||
specifier: "service:topic-tracking-state",
|
||||
});
|
||||
|
||||
autoLoadModules(this.owner, this.registry);
|
||||
this.owner.lookup("service:store");
|
||||
|
|
|
@ -69,7 +69,7 @@ export default function (customLookup = () => {}) {
|
|||
this._kvs = this._kvs || new KeyValueStore();
|
||||
return this._kvs;
|
||||
}
|
||||
if (type === "topic-tracking-state:main") {
|
||||
if (type === "service:topic-tracking-state") {
|
||||
this._tracker = this._tracker || TopicTrackingState.create();
|
||||
return this._tracker;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue