Skip to content

Instantly share code, notes, and snippets.

@odessy
Last active September 6, 2024 15:28
Show Gist options
  • Save odessy/0ab460290e7c65376336591eb222372b to your computer and use it in GitHub Desktop.
Save odessy/0ab460290e7c65376336591eb222372b to your computer and use it in GitHub Desktop.
Pipeline 6 cart js fetch custom event
window.fetch('/cart.js')
.then(function(response) {
if(response.ok){
return response.json().then(function(json) {
document.dispatchEvent(new CustomEvent('theme:cart:change', {
detail: {
cart: json,
},
bubbles: true,
}));
});
} else {
throw e;
}
}).catch(e => { console.error(e)});
document.querySelector('[data-drawer="drawer-cart"]').dispatchEvent(
new CustomEvent('theme:drawer:open', {
bubbles: false,
})
);
window.fetch('/cart.js')
.then(function(response) {
if(response.ok){
return response.json().then(function(json) {
document.dispatchEvent(new CustomEvent('theme:cart:change', {
detail: {
cart: json,
},
bubbles: true,
}));
document.querySelector('[data-drawer="drawer-cart"]').dispatchEvent(
new CustomEvent('theme:drawer:open', {
bubbles: false,
})
);
});
} else {
throw e;
}
}).catch(e => { console.error(e)});
window.fetch('/cart.js')
.then(function(response) {
if(response.ok){
return response.json().then(function(json) {
document.dispatchEvent(new CustomEvent('theme:cart:change', {
detail: {
cart: json,
},
bubbles: true,
}));
document.dispatchEvent(new CustomEvent('theme:cart:reload', {bubbles: true}));
});
} else {
throw e;
}
}).catch(e => { console.error(e)});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment