Last active
September 6, 2024 15:28
-
-
Save odessy/0ab460290e7c65376336591eb222372b to your computer and use it in GitHub Desktop.
Pipeline 6 cart js fetch custom event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document.querySelector('[data-drawer="drawer-cart"]').dispatchEvent( | |
| new CustomEvent('theme:drawer:open', { | |
| bubbles: false, | |
| }) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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