Skip to content

Commit

Permalink
Added debounce. Fixed types tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshall-slicedbread committed Sep 13, 2023
1 parent 25f1405 commit 08771f3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/infra/typesTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -72,5 +73,6 @@ export {

// Util
ContactUrlGenerator,
MapUrlGenerator
MapUrlGenerator,
debounce
}
25 changes: 25 additions & 0 deletions src/util/debounce.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 08771f3

Please sign in to comment.