UNPKG

@shopify/app-bridge-host

Version:

App Bridge Host contains middleware and components that are meant to be consumed by the app's host. The middleware and `Frame` component are responsible for facilitating messages posted between the client and host, and used to act on actions sent from the

43 lines (42 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var actions_1 = require("@shopify/app-bridge/actions"); var actions_2 = require("./actions"); /** * The default loading state * @internal */ exports.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 = exports.defaultLoadingStore; } switch (action.type) { case actions_1.Loading.ActionType.START: { return { isLoading: true, loadingCounter: state.loadingCounter + 1, }; } case actions_1.Loading.ActionType.STOP: { var currentCounter = Math.max(0, state.loadingCounter - 1); return { isLoading: currentCounter > 0, loadingCounter: currentCounter, }; } case actions_2.RESET_LOADING: { return exports.defaultLoadingStore; } default: return state; } } exports.default = loadingReducer;