Skip to content

Commit

Permalink
DEV: Set owner on widget instances (discourse#22391)
Browse files Browse the repository at this point in the history
This allows us to use `getOwner(this)` on widgets (without needing to resort to our custom `discourse-common/lib/get-owner` implementation which has a hacky fallback)
  • Loading branch information
davidtaylorhq authored Jul 3, 2023
1 parent 0790e9f commit 1b693d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ export function getRegister(obj) {
},
};

setOwner(register, owner);

return register;
}
2 changes: 2 additions & 0 deletions app/assets/javascripts/discourse/app/widgets/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { get } from "@ember/object";
import { h } from "virtual-dom";
import { isProduction } from "discourse-common/config/environment";
import { consolePrefix } from "discourse/lib/source-identifier";
import { getOwner, setOwner } from "@ember/application";

const _registry = {};

Expand Down Expand Up @@ -146,6 +147,7 @@ export default class Widget {
this.dirtyKeys = opts.dirtyKeys;

register.deprecateContainer(this);
setOwner(this, getOwner(register));

this.key = this.buildKey ? this.buildKey(attrs) : null;
this.site = register.lookup("service:site");
Expand Down

0 comments on commit 1b693d0

Please sign in to comment.