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

View File

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