DEV: Wrap Ember.run.debounce. (#11352)

We want to wrap the `Ember.run.debounce` function and internally call `Ember.run` instead when running tests.

This commit changes discourseDebounce to work the same way as `Ember.run.debounce`.

Now that `discourseDebounce` works exactly like `Ember.run.debounce`, let's replace it and only use `DiscourseDebounce` from now on.

Move debounce to discourse-common to be able to reuse it in different bundles

Keep old debounce file for backwards-compatibility
This commit is contained in:
Roman Rizzi
2020-12-10 11:01:42 -03:00
committed by GitHub
parent fb2e24a77a
commit 8b426431a4
50 changed files with 519 additions and 353 deletions

View File

@ -1,7 +1,7 @@
import { observes, on } from "discourse-common/utils/decorators";
import Component from "@ember/component";
import I18n from "I18n";
import discourseDebounce from "discourse/lib/debounce";
import discourseDebounce from "discourse-common/lib/debounce";
import { scheduleOnce } from "@ember/runloop";
export default Component.extend({
@ -33,9 +33,7 @@ export default Component.extend({
}
},
@on("init")
@observes("logs.[]")
_updateFormattedLogs: discourseDebounce(function () {
_updateFormattedLogsFunc: function () {
const logs = this.logs;
if (logs.length === 0) {
return;
@ -57,7 +55,13 @@ export default Component.extend({
this.renderLogs();
scheduleOnce("afterRender", this, this._scrollDown);
}, 150),
},
@on("init")
@observes("logs.[]")
_updateFormattedLogs() {
discourseDebounce(this, this._updateFormattedLogsFunc, 150);
},
renderLogs() {
const formattedLogs = this.formattedLogs;