@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 (61 loc) • 2.2 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var Toast = require('@shopify/app-bridge-core/actions/Toast');
var toast = require('@shopify/app-bridge-core/validate/actions/toast');
var types = require('./types.js');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var Toast__namespace = /*#__PURE__*/_interopNamespace(Toast);
var defaultToastStore = {};
function toastReducer(state, action) {
if (state === void 0) { state = defaultToastStore; }
var castAction = action;
if (castAction.type === types.LegacyFlashShow) {
castAction = tslib.__assign(tslib.__assign({}, castAction), { type: Toast__namespace.Action.SHOW });
}
else if (castAction.type === types.LegacyFlashClear) {
castAction = tslib.__assign(tslib.__assign({}, castAction), { type: Toast__namespace.Action.CLEAR });
}
if (toast.validateAction(castAction)) {
return state;
}
switch (action.type) {
case Toast__namespace.Action.SHOW:
case types.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__namespace.Action.CLEAR:
case types.LegacyFlashClear: {
return {};
}
default:
return state;
}
}
exports.default = toastReducer;
exports.defaultToastStore = defaultToastStore;