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

43 lines (40 loc) 1.14 kB
import { Loading } from '@shopify/app-bridge-core/actions'; import { RESET_LOADING } from './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 Loading.Action.START: { return { isLoading: true, loadingCounter: state.loadingCounter + 1, }; } case Loading.Action.STOP: { var currentCounter = Math.max(0, state.loadingCounter - 1); return { isLoading: currentCounter > 0, loadingCounter: currentCounter, }; } case RESET_LOADING: { return defaultLoadingStore; } default: return state; } } export { loadingReducer as default, defaultLoadingStore };