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

73 lines (68 loc) 2.46 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var Actions = require('@shopify/app-bridge-core/actions'); var navigation = require('@shopify/app-bridge-core/validate/actions/navigation'); var actions = require('./actions.js'); var defaultNavigationStore = {}; function navigationReducer(state, action) { if (state === void 0) { state = defaultNavigationStore; } switch (action.type) { case Actions.Redirect.Action.APP: case Actions.History.Action.PUSH: case Actions.History.Action.REPLACE: { var castAction = action; if (navigation.validateAction(castAction)) { return state; } var payload = castAction.payload; return { updateAction: { type: getUpdateActionType(action.type), target: Actions.Redirect.Action.APP, payload: payload, }, }; } case Actions.Redirect.Action.ADMIN_PATH: case Actions.Redirect.Action.ADMIN_SECTION: case Actions.Redirect.Action.REMOTE: { var castAction = action; if (navigation.validateAction(castAction)) { return state; } var payload = castAction.payload; var target = getUpdateActionTarget(action.type); return { updateAction: { target: target, payload: payload, }, }; } case actions.COMPLETE_ROUTE_UPDATE: { return tslib.__assign(tslib.__assign({}, state), { updateAction: undefined }); } default: return state; } } function getUpdateActionType(type) { switch (type) { case Actions.History.Action.REPLACE: return Actions.History.Action.REPLACE; case Actions.History.Action.PUSH: return Actions.History.Action.PUSH; } } function getUpdateActionTarget(type) { switch (type) { case Actions.Redirect.Action.ADMIN_PATH: return Actions.Redirect.Action.ADMIN_PATH; case Actions.Redirect.Action.ADMIN_SECTION: return Actions.Redirect.Action.ADMIN_SECTION; } return Actions.Redirect.Action.REMOTE; } exports.default = navigationReducer; exports.defaultNavigationStore = defaultNavigationStore;