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

68 lines (63 loc) 2.05 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var Actions = require('@shopify/app-bridge-core/actions'); var menu = require('@shopify/app-bridge-core/validate/actions/menu'); var utilities = require('../utilities.js'); /** * Returns a mapped object with methods for dispatching Menu actions * @internal * */ var menuActionCreatorsMap = { updateNavigationMenu: Actions.NavigationMenu.update, }; /** * The default loading state * @internal */ var defaultMenuStore = { navigationMenu: undefined, channelMenu: undefined, }; /** * Returns the updated menu state * @internal */ function menuReducer(state, action) { if (state === void 0) { state = defaultMenuStore; } switch (action.type) { case Actions.NavigationMenu.Action.UPDATE: { // Need to cast the action to the correct type var castAction = action; if (menu.validateAction(castAction)) { return state; } return tslib.__assign(tslib.__assign({}, state), { navigationMenu: castAction.payload }); } case Actions.ChannelMenu.Action.UPDATE: { var castAction = action; if (menu.validateAction(castAction)) { return state; } return tslib.__assign(tslib.__assign({}, state), { channelMenu: castAction.payload }); } default: return state; } } /** * An object containing the key, actions, initial state and reducer of the Menu feature * Can be used with the `withFeature` decorator to add the reducer * and then make its actions and store available to the wrapped component * @public * */ var feature = { actions: menuActionCreatorsMap, key: 'menu', initialState: defaultMenuStore, reducer: utilities.resetStateReducer(menuReducer), }; exports.default = menuReducer; exports.defaultMenuStore = defaultMenuStore; exports.feature = feature; exports.menuActionCreatorsMap = menuActionCreatorsMap;