Skip to content

Commit

Permalink
fix: show/hide events not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Aug 12, 2020
1 parent 7fd7c7b commit 78c5de6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/delivery-options/DeliveryOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import * as CONFIG from '@/data/keys/configKeys';
import * as EVENTS from '@/config/eventConfig';
import * as FORM from '@/config/formConfig';
import { NL, addressRequirements } from '@/config/localeConfig';
import { ADDRESS_ERROR } from '@/config/errorConfig';
import Errors from '@/delivery-options/components/Errors';
import Loader from '@/delivery-options/components/Loader';
import Modal from '@/delivery-options/components/Modal';
import { addressRequirements } from '@/config/localeConfig';
import { configBus } from '@/delivery-options/config/configBus';
import debounce from 'lodash-es/debounce';
import { fetchAllCarriers } from '@/delivery-options/data/carriers/fetchAllCarriers';
Expand Down Expand Up @@ -111,20 +111,25 @@ export default {
}
this.showDeliveryOptions = true;
this.listeners.update();
this.fakeShowDeliveryOptions = true;
document.addEventListener(EVENTS.UPDATE_DELIVERY_OPTIONS, this.listeners.update);
this.listeners.update();
},
hide: () => {
this.$configBus.exportValues = {};
this.fakeShowDeliveryOptions = false;
const listenForLastUpdate = () => {
const onLastUpdate = () => {
this.showDeliveryOptions = false;
document.removeEventListener(EVENTS.UPDATE_DELIVERY_OPTIONS, this.listeners.update);
document.removeEventListener(EVENTS.UPDATED_DELIVERY_OPTIONS, listenForLastUpdate);
document.removeEventListener(EVENTS.UPDATED_DELIVERY_OPTIONS, onLastUpdate);
clearTimeout(lastUpdateTimeout);
};
document.addEventListener(EVENTS.UPDATED_DELIVERY_OPTIONS, listenForLastUpdate);
const LAST_UPDATE_CUTOFF = 500;
const lastUpdateTimeout = setTimeout(onLastUpdate, LAST_UPDATE_CUTOFF);
document.addEventListener(EVENTS.UPDATED_DELIVERY_OPTIONS, onLastUpdate);
},
update: debounce(this.getDeliveryOptions, DEBOUNCE_DELAY),
updateExternal: debounce(this.updateExternal, DEBOUNCE_DELAY),
Expand All @@ -148,7 +153,7 @@ export default {
}
const { cc } = this.$configBus.address;
const requirements = addressRequirements[addressRequirements.hasOwnProperty(cc) ? cc : 'nl'];
const requirements = addressRequirements[addressRequirements.hasOwnProperty(cc) ? cc : NL];
const meetsRequirements = (item) => {
return this.$configBus.address.hasOwnProperty(item) && this.$configBus.address[item];
Expand Down Expand Up @@ -344,8 +349,8 @@ export default {
* Trigger an update on the checkout. Throttled to avoid overloading the external platform with updates.
*
* @param {Object|Boolean} data - If data is false, sends empty update.
* @property {String} data.name - Name of the changed option (if called through update).
* @property {*} data.value - New value of the changed option (if called through update).
* @param {String} data.name - Name of the changed option (if called through update).
* @param {*} data.value - New value of the changed option (if called through update).
*/
updateExternal(data) {
const isEmptied = data === false || (data.name === FORM.DELIVERY && data.value === null);
Expand Down

0 comments on commit 78c5de6

Please sign in to comment.