Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EAK-516] Add embedded debounce implementation to not rely on jquery-debounce module persistence #520

Merged
merged 9 commits into from
May 31, 2024
6 changes: 3 additions & 3 deletions docs/content/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ seoTitle: Installation - Exadel Authoring Kit
<dependency>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit-core</artifactId>
<version>2.4.1</version> <!-- Prefer the latest stable version whenever possible -->
<version>2.5.1</version> <!-- Prefer the latest stable version whenever possible -->
<scope>provided</scope> <!-- Do not use compile or runtime scope!-->
</dependency>
```
Expand All @@ -21,7 +21,7 @@ seoTitle: Installation - Exadel Authoring Kit
<plugin>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit-plugin</artifactId>
<version>2.4.1</version>
<version>2.5.1</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -79,7 +79,7 @@ You need to do two steps.
<dependency>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-authoring-kit-all</artifactId>
<version>2.4.1</version>
<version>2.5.1</version>
<type>content-package</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions docs/website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ui.apps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui.apps/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "depends-on",
"description": "A clientlib that executes defined action on dependent fields",
"version": "2.4.1",
"version": "2.5.1",
"private": true,
"devDependencies": {
"eslint": "^8.45.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
};

// Track new component initialization
$document.off('foundation-contentloaded.dependsOn')
$document
.off('foundation-contentloaded.dependsOn')
.on('foundation-contentloaded.dependsOn', (e) => ns.initialize((e && e.target) || document));

// Track reference field changes
Expand All @@ -72,13 +73,14 @@
.off('change:value.dependsOn').on('change:value.dependsOn', '[data-dependsonref]', handleChange);

// Track input event
const handleChangeDebounced = $.debounce(750, handleChange);
$document
.off('input.dependsOn').on('input', '[data-dependsonref]:not([data-dependsonreflazy])', handleChangeDebounced);
.off('input.dependsOn')
.on('input', '[data-dependsonref]:not([data-dependsonreflazy])', ns.debounce(handleChange, 750));

// Track collection change to update dynamic references
$document
.off('coral-collection:remove.dependsOn coral-collection:add.dependsOn').on('coral-collection:remove.dependsOn coral-collection:add.dependsOn', 'coral-multifield', (e) => {
.off('coral-collection:remove.dependsOn coral-collection:add.dependsOn')
.on('coral-collection:remove.dependsOn coral-collection:add.dependsOn', 'coral-multifield', (e) => {
// We should actualize references on coral-collection:remove and coral-collection:add too.
ns.ElementReferenceRegistry.handleChange(e);
ns.ElementReferenceRegistry.actualize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,17 @@
}
return fn;
};

/**
* Debounce function wrapper
* @param {function} fn
* @param {number} timeout
*/
ns.debounce = function (fn, timeout) {
let timer;
return function (...args) {
clearTimeout(timer);
timer = setTimeout(() => fn.apply(this, args), timeout);
};
};
})(Granite.$, Granite.DependsOnPlugin = (Granite.DependsOnPlugin || {}));
Loading