UNPKG

@shopify/app-bridge-host

Version:

App Bridge Host contains components and middleware to be consumed by the app's host, as well as the host itself. The middleware and `Frame` component are responsible for facilitating communication between the client and host, and used to act on actions se

48 lines (43 loc) 1.26 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var Actions = require('@shopify/app-bridge-core/actions'); var actions = require('./actions.js'); /** * The default loading state * @internal */ var defaultLoadingStore = { isLoading: false, loadingCounter: 0, }; /** * Returns the updated loading state * @remarks the loading state is managed via counter which enables * multiple consumers to start/stop loading * @internal */ function loadingReducer(state, action) { if (state === void 0) { state = defaultLoadingStore; } switch (action.type) { case Actions.Loading.Action.START: { return { isLoading: true, loadingCounter: state.loadingCounter + 1, }; } case Actions.Loading.Action.STOP: { var currentCounter = Math.max(0, state.loadingCounter - 1); return { isLoading: currentCounter > 0, loadingCounter: currentCounter, }; } case actions.RESET_LOADING: { return defaultLoadingStore; } default: return state; } } exports.default = loadingReducer; exports.defaultLoadingStore = defaultLoadingStore;