♻️ Extract button-refresh logic to own helper file

- Exrtract repeat event-init logic to new helper file
- Remove the jQuery dependency
This commit is contained in:
Philipp Stracker 2024-06-26 18:16:54 +02:00
parent 5ed2f37bd4
commit 4c10c37782
No known key found for this signature in database
4 changed files with 46 additions and 32 deletions

View file

@ -1,7 +1,7 @@
import {loadCustomScript} from "@paypal/paypal-js";
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
import GooglepayManager from "./GooglepayManager";
import { debounce } from '../../../ppcp-blocks/resources/js/Helper/debounce';
import {setupButtonEvents} from '../../../ppcp-button/resources/js/modules/Helper/ButtonRefreshHelper';
(function ({
buttonConfig,
@ -16,20 +16,11 @@ import { debounce } from '../../../ppcp-blocks/resources/js/Helper/debounce';
manager.init();
};
const refresh = debounce(function() {
setupButtonEvents(function() {
if (manager) {
manager.reinit();
}
}, 50);
jQuery(document).on('ppcp_refresh_payment_buttons', refresh);
jQuery(document.body).on('updated_cart_totals updated_checkout', refresh);
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
setTimeout(() => {
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', refresh);
}, 1000);
});
document.addEventListener(
'DOMContentLoaded',