Last active
April 4, 2017 18:59
-
-
Save lkostrowski/9f7a6faa94610a3e29a714a602d02bd5 to your computer and use it in GitHub Desktop.
This file contains 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
import eventHub from 'services/_eventBus'; | |
const cartRequestUrl = '/get/basket' // Url to our backend | |
function getBasket( ) { | |
eventHub.$emit('basket:loading'); // Emit loading so components can show loaders | |
// Make api call | |
axios.get( cartRequestUrl ).then( ( response ) => { | |
emitBasketUpdate(response.data); | |
} ); | |
} | |
function emitBasketUpdate() { | |
eventHub.$emit('basket:updated', {products: basketData}); // Emit updated basket and pass fetched data | |
} | |
// Subscribe on... | |
function init () { | |
// ...first basket page load | |
eventHub.$on('basketpage:loaded', () => { | |
getBasket(); | |
}); | |
// ... every upcoming basket change | |
eventHub.$on('basket:changed', () => { | |
getBasket(); | |
}); | |
} | |
export {init}; // And init in in your root js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment