From 3da00ddaa103ab71e15ccd285d841819913b524a Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Tue, 22 Dec 2020 14:45:33 -0300 Subject: [PATCH] DEV: Use the new discourseDebounce function wrapper. (#22) 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. --- .../knowledge-explorer-search.js.es6 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/knowledge-explorer-search.js.es6 b/assets/javascripts/discourse/components/knowledge-explorer-search.js.es6 index 9a8bb09..335ed57 100644 --- a/assets/javascripts/discourse/components/knowledge-explorer-search.js.es6 +++ b/assets/javascripts/discourse/components/knowledge-explorer-search.js.es6 @@ -1,12 +1,22 @@ import Component from "@ember/component"; -import debounce from "discourse/lib/debounce"; +import { debounce } from "@ember/runloop"; +import discourseDebounce from "discourse-common/lib/debounce"; export default Component.extend({ classNames: "knowledge-explorer-search", - debouncedSearch: debounce(function (term) { - this.onSearch(term); - }, 500), + debouncedSearch(term) { + // TODO: Use discouseDebounce when discourse 2.7 gets released. + const debounceFunc = discourseDebounce || debounce; + + debounceFunc( + this, + function () { + this.onSearch(term); + }, + 500 + ); + }, actions: { onSearchTermChange(term) {