UNPKG

@shopify/app-bridge-core

Version:

**[Join our team and work on libraries like this one.](https://www.shopify.ca/careers)**

72 lines (69 loc) 1.98 kB
import { actionWrapper, getEventNameSpace, getMergedProps } from '../../helper.js'; import { ActionSet } from '../../ActionSet.js'; import { Group } from '../../types.js'; import { Action as Action$1 } from '../../Navigation/Redirect/index.js'; var Action; (function (Action) { Action["UPDATE"] = "UPDATE"; })(Action || (Action = {})); function update(group, component, updatePayload) { const { id } = component; const { label, destination } = updatePayload; const linkPayload = { ...updatePayload, id, label, destination, }; return actionWrapper({ group, type: getEventNameSpace(group, Action.UPDATE, component), payload: linkPayload, }); } class AppLink extends ActionSet { label = ''; destination = ''; constructor(app, options) { super(app, Group.Link, Group.Link); this.set(options, false); } get options() { const { label, destination } = this; return { label, destination, redirectType: Action$1.APP, }; } get payload() { const { label, destination, redirectType } = this.options; const path = destination; return { id: this.id, label, destination: { path }, redirectType, }; } set(options, shouldUpdate = true) { const { label, destination } = getMergedProps(this.options, options); this.label = label; this.destination = destination; if (shouldUpdate) { this.dispatch(Action.UPDATE); } return this; } dispatch(action) { switch (action) { case Action.UPDATE: { const updateAction = update(this.group, this.component, this.payload); this.app.dispatch(updateAction); break; } } return this; } } export { Action, AppLink, update };