UNPKG

@shopify/app-bridge-core

Version:

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

91 lines (88 loc) 2.43 kB
import { actionWrapper, getMergedProps } from '../helper.js'; import { ActionSet } from '../ActionSet.js'; import { Group } from '../types.js'; /** * Action for the Leave Confirmation group * @public */ var Action; (function (Action) { Action["ENABLE"] = "APP::LEAVE_CONFIRMATION::ENABLE"; Action["DISABLE"] = "APP::LEAVE_CONFIRMATION::DISABLE"; Action["CONFIRM"] = "APP::LEAVE_CONFIRMATION::CONFIRM"; })(Action || (Action = {})); function enable(payload = {}) { return actionWrapper({ group: Group.LeaveConfirmation, payload, type: Action.ENABLE, }); } function disable(payload = {}) { return actionWrapper({ group: Group.LeaveConfirmation, payload, type: Action.DISABLE, }); } function confirm(payload = {}) { return actionWrapper({ group: Group.LeaveConfirmation, payload, type: Action.CONFIRM, }); } /** * Leave Confirmation action set */ class LeaveConfirmation extends ActionSet { options; /** * Returns a new instance of a Leave Confirmation action set * @param app the client application */ constructor(app, options = {}) { super(app, Group.LeaveConfirmation, Group.LeaveConfirmation); this.options = options; this.set(options); } /** * Returns the action set payload */ get payload() { return { id: this.id, ...this.options, }; } set(options) { this.options = getMergedProps(this.options, options); return this; } /** * Dispatches a given action with the action set payload * @param action the action enum * @returns the action set instance */ dispatch(action) { switch (action) { case Action.ENABLE: { const enableAction = enable(this.payload); this.app.dispatch(enableAction); break; } case Action.DISABLE: { const disableAction = disable(this.payload); this.app.dispatch(disableAction); break; } case Action.CONFIRM: { const confirmAction = confirm(this.payload); this.app.dispatch(confirmAction); break; } } return this; } } export { Action, LeaveConfirmation, confirm, disable, enable };