mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Correctly debounce various functions (#18673)
Debouncing inline anonymous functions does not work. This fixes all instances of that error by extracting the function or using the new `@debounce(delay)` decorator
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
/* global Pikaday:true */
|
||||
import computed, { observes } from "discourse-common/utils/decorators";
|
||||
import computed, {
|
||||
debounce,
|
||||
observes,
|
||||
} from "discourse-common/utils/decorators";
|
||||
import Component from "@ember/component";
|
||||
import EmberObject, { action } from "@ember/object";
|
||||
import I18n from "I18n";
|
||||
import { INPUT_DELAY } from "discourse-common/config/environment";
|
||||
import { Promise } from "rsvp";
|
||||
import { cookAsync } from "discourse/lib/text";
|
||||
import discourseDebounce from "discourse-common/lib/debounce";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
import { notEmpty } from "@ember/object/computed";
|
||||
@ -59,25 +61,19 @@ export default Component.extend({
|
||||
},
|
||||
|
||||
@observes("computedConfig.{from,to,options}", "options", "isValid", "isRange")
|
||||
_renderPreview() {
|
||||
discourseDebounce(
|
||||
this,
|
||||
function () {
|
||||
const markup = this.markup;
|
||||
if (markup) {
|
||||
cookAsync(markup).then((result) => {
|
||||
this.set("currentPreview", result);
|
||||
schedule("afterRender", () => {
|
||||
applyLocalDates(
|
||||
document.querySelectorAll(".preview .discourse-local-date"),
|
||||
this.siteSettings
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
INPUT_DELAY
|
||||
);
|
||||
@debounce(INPUT_DELAY)
|
||||
async _renderPreview() {
|
||||
if (this.markup) {
|
||||
const result = await cookAsync(this.markup);
|
||||
this.set("currentPreview", result);
|
||||
|
||||
schedule("afterRender", () => {
|
||||
applyLocalDates(
|
||||
document.querySelectorAll(".preview .discourse-local-date"),
|
||||
this.siteSettings
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@computed("date", "toDate", "toTime")
|
||||
|
Reference in New Issue
Block a user