@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
10 lines • 1.13 kB
JavaScript
import'rxjs/add/operator/debounceTime';import event from'@shopgate/pwa-core/classes/Event';import registerEvents from'@shopgate/pwa-core/commands/registerEvents';import{appDidStart$}from'@shopgate/pwa-common/streams/app';import{historyReset}from'@shopgate/pwa-common/actions/router';import successCheckout from"../action-creators/successCheckout";import{checkoutSucceeded$}from"../streams";import{getCartProducts}from"../../cart/selectors";/**
* Checkout subscriptions.
* @param {Function} subscribe The subscribe function.
*/var checkout=function checkout(subscribe){/**
* Gets triggered when the app starts.
*/subscribe(appDidStart$,function(_ref){var dispatch=_ref.dispatch,getState=_ref.getState;// Register for the app event that is triggered when the checkout process is finished
registerEvents(['checkoutSuccess']);event.addCallback('checkoutSuccess',function(){dispatch(successCheckout(getCartProducts(getState())));});});/**
* After success checkout
*/subscribe(checkoutSucceeded$,function(_ref2){var dispatch=_ref2.dispatch;// Reset navigation history
dispatch(historyReset());});};export default checkout;