Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { ObservableContainer } from 'src/bootstrapper/connectData/index';
import { oneRouter } from '@skava/router';
import { minicartSidebar } from 'src/views/layouts/Sidebarz';
import { state as headerState } from '../../organisms/Header/state';
import { application } from 'state/application';
import { cartContainer, updateCart } from 'state/cart/container';
let updateTimeout;
class ShippingCartContainer extends ObservableContainer {
    updateWhenThreadIsFree(isFromInit) {
        console.debug('[MiniCart] updateWhenThreadIsFree');
        clearTimeout(updateTimeout);
        const promiseOfFreedom = (resolve) => {
            // will call updateCart, then resolve
            const onFree = () => __awaiter(this, void 0, void 0, function* () {
                yield updateCart(isFromInit);
                resolve();
            });
            // will call on free, an async function, after 1s
            updateTimeout = setTimeout(onFree, 1000);
        };
        // returning a promise here allows us to await, or use .then
        return new Promise(promiseOfFreedom);
        // @note - I put this as 1000 for sidebar start, but 5-10,000 + requestAnimationFrame would be better
    }
    subscribeToRouteChanges() {
        // this func returned true,  even sidebarStore.isVisible is true
        if (minicartSidebar.isVisible === false) {
            return;
        }
        minicartSidebar.setIsVisible(false);
    }
    onRouteChange() {
        minicartSidebar.setIsVisible(false);
    }
    handleClick() {
        console.log('[MiniCart] click');
        if (headerState.isMenuDropDownVisible) {
            headerState.hide();
        }
        if (!application.isDesktop && application.isTabletOrSmaller) {
            oneRouter.update('/checkout');
            return;
        }
        if (minicartSidebar.isVisible === false) {
            shoppingCartContainer.updateWhenThreadIsFree(false);
            cartContainer.fetchZipcode();
        }
        minicartSidebar.setIsVisible(!minicartSidebar.isVisible);
    }
}
const shoppingCartContainer = new ShippingCartContainer();
export { shoppingCartContainer };
export default shoppingCartContainer;
//# sourceMappingURL=container.js.map