UNPKG

@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

42 lines (41 loc) 1.66 kB
"use strict"; 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); }; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); var validator_1 = require("@shopify/app-bridge/actions/validator"); var actions_1 = require("../../../../actions"); var embeddedApp_1 = __importStar(require("../../embeddedApp")); var combinedReducers = embeddedApp_1.default(); function isPrivateAppAction(action) { return (!!action && !!action.type && (action.type.indexOf('PRIVATE_APP::') === 0 || action.type === actions_1.API_CLIENT_LOAD)); } exports.isPrivateAppAction = isPrivateAppAction; function appBridgeReducer(state, action) { if (state === void 0) { state = embeddedApp_1.defaultStore; } var appBridgeAction = validator_1.isAppBridgeAction(action); if (appBridgeAction || isPrivateAppAction(action)) { if (appBridgeAction) window.postMessage(JSON.stringify(action), '*'); return __assign({}, state, combinedReducers(state, action)); } return state; } exports.default = appBridgeReducer;