DEV: Make `@afterRender` do just that, no extra `next()` (#15086)

This commit is contained in:
Jarek Radosz 2021-11-26 20:16:08 +01:00 committed by GitHub
parent 4229e3f22c
commit fac6cc0778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 26 deletions

View File

@ -1,4 +1,4 @@
import { bind as emberBind, next, schedule } from "@ember/runloop";
import { bind as emberBind, schedule } from "@ember/runloop";
import decoratorAlias from "discourse-common/utils/decorator-alias";
import extractValue from "discourse-common/utils/extract-value";
import handleDescriptor from "discourse-common/utils/handle-descriptor";
@ -19,12 +19,10 @@ export default function discourseComputedDecorator(...params) {
export function afterRender(target, name, descriptor) {
const originalFunction = descriptor.value;
descriptor.value = function () {
next(() => {
schedule("afterRender", () => {
if (this.element && !this.isDestroying && !this.isDestroyed) {
return originalFunction.apply(this, arguments);
}
});
schedule("afterRender", () => {
if (this.element && !this.isDestroying && !this.isDestroyed) {
return originalFunction.apply(this, arguments);
}
});
};
}

View File

@ -1,5 +1,4 @@
import Component from "@ember/component";
import { afterRender } from "discourse-common/utils/decorators";
import { ajax } from "discourse/lib/ajax";
import { cookAsync } from "discourse/lib/text";
import { loadOneboxes } from "discourse/lib/load-oneboxes";
@ -10,31 +9,26 @@ const CookText = Component.extend({
didReceiveAttrs() {
this._super(...arguments);
cookAsync(this.rawText).then((cooked) => {
this.set("cooked", cooked);
if (this.paintOneboxes) {
this._loadOneboxes();
}
this._resolveUrls();
});
},
@afterRender
_loadOneboxes() {
const refresh = false;
didRender() {
this._super(...arguments);
loadOneboxes(
this.element,
ajax,
this.topicId,
this.categoryId,
this.siteSettings.max_oneboxes_per_post,
refresh
);
},
if (this.paintOneboxes) {
loadOneboxes(
this.element,
ajax,
this.topicId,
this.categoryId,
this.siteSettings.max_oneboxes_per_post,
false // refresh
);
}
@afterRender
_resolveUrls() {
resolveAllShortUrls(ajax, this.siteSettings, this.element, this.opts);
},
});