@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
52 lines (51 loc) • 1.85 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var actions_1 = require("@shopify/app-bridge/actions");
var toast_1 = require("@shopify/app-bridge/validate/actions/toast");
var types_1 = require("./types");
exports.defaultToastStore = {};
function toastReducer(state, action) {
if (state === void 0) { state = exports.defaultToastStore; }
var castAction = action;
if (castAction.type === types_1.LegacyFlashShow) {
castAction = __assign({}, castAction, { type: actions_1.Toast.ActionType.SHOW });
}
else if (castAction.type === types_1.LegacyFlashClear) {
castAction = __assign({}, castAction, { type: actions_1.Toast.ActionType.CLEAR });
}
if (toast_1.validateAction(castAction)) {
return state;
}
switch (action.type) {
case actions_1.Toast.ActionType.SHOW:
case types_1.LegacyFlashShow: {
var _a = castAction.payload, id = _a.id, duration = _a.duration, message = _a.message, isError = _a.isError;
return {
content: {
id: id,
duration: duration,
message: message,
error: Boolean(isError),
},
};
}
case actions_1.Toast.ActionType.CLEAR:
case types_1.LegacyFlashClear: {
return {};
}
default:
return state;
}
}
exports.default = toastReducer;