DEV: Use the new discourseDebounce function wrapper. (#85)

We recently merged a Discourse core's PR to replace usages of Ember's debounce and discourseDebounce with a new debounce wrapper. The new wrapper works exactly like Ember's debounce but internally calls "run" when called in test mode.

This PR replaces all usages of other debounce functions with the new wrapper and fallbacks to Ember's debounce for backward-compatibility.
This commit is contained in:
Roman Rizzi 2021-01-05 13:09:21 -03:00 committed by GitHub
parent ae271dafad
commit c6a11d9280
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 5 deletions

View File

@ -2,7 +2,8 @@ import {
default as computed, default as computed,
observes, observes,
} from "discourse-common/utils/decorators"; } from "discourse-common/utils/decorators";
import debounce from "discourse/lib/debounce"; import discourseDebounce from "discourse-common/lib/debounce";
import debounce from "@ember/runloop";
export default Ember.Component.extend({ export default Ember.Component.extend({
actions: { actions: {
@ -113,10 +114,19 @@ export default Ember.Component.extend({
}, },
@observes("filter") @observes("filter")
triggerFilter: debounce(function () { triggerFilter() {
// TODO: Use discouseDebounce after the 2.7 release.
let debounceFunc = discourseDebounce || debounce;
debounceFunc(
this,
function () {
this.set("filteredTables", this.filterTables(this.transformedSchema)); this.set("filteredTables", this.filterTables(this.transformedSchema));
this.set("loading", false); this.set("loading", false);
}, 500), },
500
);
},
@observes("filter") @observes("filter")
setLoading() { setLoading() {