From 08771f3a5cf170920898307d43fb9cedaae8e126 Mon Sep 17 00:00:00 2001 From: James Hall Date: Wed, 13 Sep 2023 14:22:56 +0100 Subject: [PATCH] Added debounce. Fixed types tree. --- src/infra/typesTree.js | 6 +++++- src/plugin.js | 4 +++- src/util/debounce.js | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/util/debounce.js diff --git a/src/infra/typesTree.js b/src/infra/typesTree.js index bc82f1e..9ad5132 100644 --- a/src/infra/typesTree.js +++ b/src/infra/typesTree.js @@ -13,7 +13,7 @@ class SharedoTypesTree { this.initialized = true; } - isDerivedFrom(type, parentTypes) { + isDerivedFrom(type, parentTypes, trueDescendant = false) { if (!this.initialized) { throw new Error("Tree not initialized."); } @@ -22,6 +22,10 @@ class SharedoTypesTree { const parent = this.find(parentType); if (parent) { + if (!trueDescendant && parent.systemName === type) { + return true; + } + const child = this.find(type, parent); if (child) { diff --git a/src/plugin.js b/src/plugin.js index 5ec154b..f405476 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -23,6 +23,7 @@ import VEditableExpansionPanelHeader from "./components/VEditableExpansionPanelH import ContactUrlGenerator from "./util/contactUrl.js"; import MapUrlGenerator from "./util/mapUrl.js"; +import debounce from "./util/debounce.js"; export default { @@ -72,5 +73,6 @@ export { // Util ContactUrlGenerator, - MapUrlGenerator + MapUrlGenerator, + debounce } diff --git a/src/util/debounce.js b/src/util/debounce.js new file mode 100644 index 0000000..c1e429e --- /dev/null +++ b/src/util/debounce.js @@ -0,0 +1,25 @@ +const debounce = function (func, wait, immediate) { + let timeout; + return function () { + const context = this; + const args = arguments; + + const later = function () { + timeout = null; + if (!immediate) { + func.apply(context, args); + } + }; + + const callNow = immediate && !timeout; + + clearTimeout(timeout); + timeout = setTimeout(later, wait); + + if (callNow) { + func.apply(context, args); + } + } +} + +export default debounce; \ No newline at end of file