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.47 kB
import { __assign } from 'tslib'; import * as Toast from '@shopify/app-bridge-core/actions/Toast'; import { validateAction } from '@shopify/app-bridge-core/validate/actions/toast'; import { LegacyFlashShow, LegacyFlashClear } from './types.js'; var defaultToastStore = {}; function toastReducer(state, action) { if (state === void 0) { state = defaultToastStore; } var castAction = action; if (castAction.type === LegacyFlashShow) { castAction = __assign(__assign({}, castAction), { type: Toast.Action.SHOW }); } else if (castAction.type === LegacyFlashClear) { castAction = __assign(__assign({}, castAction), { type: Toast.Action.CLEAR }); } if (validateAction(castAction)) { return state; } switch (action.type) { case Toast.Action.SHOW: case LegacyFlashShow: { var _a = castAction.payload, id = _a.id, duration = _a.duration, message = _a.message, isError = _a.isError, action_1 = _a.action; return { content: { id: id, duration: duration, message: message, error: Boolean(isError), action: action_1, }, }; } case Toast.Action.CLEAR: case LegacyFlashClear: { return {}; } default: return state; } } export { toastReducer as default, defaultToastStore };