@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
61 lines (58 loc) • 1.87 kB
JavaScript
import { __assign } from 'tslib';
import { NavigationMenu, ChannelMenu } from '@shopify/app-bridge-core/actions';
import { validateAction } from '@shopify/app-bridge-core/validate/actions/menu';
import { resetStateReducer } from '../utilities.js';
/**
* Returns a mapped object with methods for dispatching Menu actions
* @internal
* */
var menuActionCreatorsMap = {
updateNavigationMenu: 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 NavigationMenu.Action.UPDATE: {
// Need to cast the action to the correct type
var castAction = action;
if (validateAction(castAction)) {
return state;
}
return __assign(__assign({}, state), { navigationMenu: castAction.payload });
}
case ChannelMenu.Action.UPDATE: {
var castAction = action;
if (validateAction(castAction)) {
return state;
}
return __assign(__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: resetStateReducer(menuReducer),
};
export { menuReducer as default, defaultMenuStore, feature, menuActionCreatorsMap };