DEV: Teardown leaky page:changed `appEvent`s between tests
This commit is contained in:
parent
d2ddb82022
commit
0bec323204
|
@ -6,15 +6,21 @@ export default {
|
|||
initialize(container) {
|
||||
// workaround for Safari on iOS 14.3
|
||||
// seems it has started using opengraph tags when sharing
|
||||
let appEvents = container.lookup("service:app-events");
|
||||
const ogTitle = document.querySelector("meta[property='og:title']"),
|
||||
ogUrl = document.querySelector("meta[property='og:url']");
|
||||
this.appEvents = container.lookup("service:app-events");
|
||||
this.ogTitle = document.querySelector("meta[property='og:title']");
|
||||
this.ogUrl = document.querySelector("meta[property='og:url']");
|
||||
|
||||
if (ogTitle && ogUrl) {
|
||||
appEvents.on("page:changed", (data) => {
|
||||
ogTitle.setAttribute("content", data.title);
|
||||
ogUrl.setAttribute("content", getAbsoluteURL(data.url));
|
||||
});
|
||||
if (this.ogTitle && this.ogUrl) {
|
||||
this.appEvents.on("page:changed", this, this.updateOgAttributes);
|
||||
}
|
||||
},
|
||||
|
||||
updateOgAttributes(data) {
|
||||
this.ogTitle.setAttribute("content", data.title);
|
||||
this.ogUrl.setAttribute("content", getAbsoluteURL(data.url));
|
||||
},
|
||||
|
||||
teardown() {
|
||||
this.appEvents.off("page:changed", this, this.updateOgAttributes);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue