@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
35 lines (32 loc) • 1.47 kB
JavaScript
import { __assign } from 'tslib';
import * as TitleBar from '@shopify/app-bridge-core/actions/TitleBar';
import { validateAction } from '@shopify/app-bridge-core/validate/actions/titleBar';
import { SET_APP_INFO, SET_PAGINATION } from './actions.js';
var defaultTitlebarStore = null;
function titleBarReducer(state, action) {
if (state === void 0) { state = defaultTitlebarStore; }
switch (action.type) {
case TitleBar.Action.UPDATE: {
// Need to cast the action to the correct type
var castAction = action;
if (validateAction(castAction)) {
return state;
}
var _a = castAction.payload, title = _a.title, buttons = _a.buttons, breadcrumbs = _a.breadcrumbs;
return __assign(__assign({}, state), { title: title, breadcrumbs: breadcrumbs, buttons: buttons });
}
case SET_PAGINATION: {
// Need to cast the action to the correct type
var castAction = action;
return __assign(__assign({}, state), { pagination: castAction.payload });
}
case SET_APP_INFO: {
var castAction = action;
var currentAppInfo = (state && state.appInfo) || {};
return __assign(__assign({}, state), { appInfo: __assign(__assign({}, currentAppInfo), castAction.payload) });
}
default:
return state;
}
}
export { titleBarReducer as default, defaultTitlebarStore };