Skip to content

Commit

Permalink
allow manual showing and hiding of the delivery options
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Oct 3, 2019
1 parent 070760f commit e87984b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@myparcel/checkout",
"version": "3.0.17",
"version": "3.0.18",
"types": "index.d.ts",
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
22 changes: 14 additions & 8 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export default {
* Event listeners object. Stored here so we can add and remove them easily.
*/
listeners: {
show: () => {
this.showDeliveryOptions = true;
this.listeners.update();
document.addEventListener(EVENTS.UPDATE_DELIVERY_OPTIONS, this.listeners.update);
},
hide: () => {
this.showDeliveryOptions = false;
document.removeEventListener(EVENTS.UPDATE_DELIVERY_OPTIONS, this.listeners.update);
},
update: debounce(this.getDeliveryOptions, debounceDelay),
updateExternal: debounce(this.updateExternal, debounceDelay),
error: (e) => {
Expand All @@ -96,10 +105,6 @@ export default {
},
computed: {
configBus() {
return this.$configBus;
},
/**
* False if:
* - CC is undefined
Expand Down Expand Up @@ -153,7 +158,7 @@ export default {
hasSomethingToShow() {
return this.$configBus.isValidCountry
&& (this.$configBus.isEnabledInAnyCarrier(ALLOW_PICKUP_LOCATIONS)
|| this.$configBus.isEnabledInAnyCarrier(ALLOW_DELIVERY_OPTIONS));
|| this.$configBus.isEnabledInAnyCarrier(ALLOW_DELIVERY_OPTIONS));
},
/**
Expand All @@ -169,8 +174,9 @@ export default {
},
created() {
this.listeners.update();
document.addEventListener(EVENTS.UPDATE_DELIVERY_OPTIONS, this.listeners.update);
this.listeners.show();
document.addEventListener(EVENTS.SHOW_DELIVERY_OPTIONS, this.listeners.show);
document.addEventListener(EVENTS.HIDE_DELIVERY_OPTIONS, this.listeners.hide);
// Add the new data to the values object
this.$configBus.$on(EVENTS.UPDATE, this.$configBus.updateExternalData);
Expand Down Expand Up @@ -288,7 +294,7 @@ export default {
EVENTS.UPDATED_DELIVERY_OPTIONS,
{
detail: this.$configBus.exportValues,
}
},
));
},
},
Expand Down
18 changes: 16 additions & 2 deletions src/config/data/eventConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* configBus events
/**
* ConfigBus events.
*
* These are only used for and by the configBus so they don't need to be namespaced.
*/
Expand Down Expand Up @@ -57,3 +57,17 @@ export const UPDATED_ADDRESS = 'myparcel_updated_address';
* @type {string}
*/
export const UPDATED_DELIVERY_OPTIONS = 'myparcel_updated_delivery_options';

/**
* Manually show the delivery options. The update listener has to be re-enabled after this.
*
* @type {String}
*/
export const SHOW_DELIVERY_OPTIONS = 'myparcel_show_delivery_options';

/**
* Manually hide the delivery options. Should remove the update listener.
*
* @type {String}
*/
export const HIDE_DELIVERY_OPTIONS = 'myparcel_hide_delivery_options';

0 comments on commit e87984b

Please sign in to comment.