@shopify/app-bridge-core
Version:
**[Join our team and work on libraries like this one.](https://www.shopify.ca/careers)**
85 lines (82 loc) • 2.11 kB
JavaScript
import { actionWrapper, getMergedProps } from '../helper.js';
import { ActionSet } from '../ActionSet.js';
import { Group } from '../types.js';
/**
* Action for the Feedback Modal group
* @public
*/
var Action;
(function (Action) {
Action["OPEN"] = "APP::FEEDBACK_MODAL::OPEN";
Action["CLOSE"] = "APP::FEEDBACK_MODAL::CLOSE";
})(Action || (Action = {}));
function open(payload) {
return actionWrapper({
group: Group.FeedbackModal,
payload,
type: Action.OPEN,
});
}
function close(payload) {
return actionWrapper({
group: Group.FeedbackModal,
payload,
type: Action.CLOSE,
});
}
/**
* FeedbackModal action set
*/
class FeedbackModal extends ActionSet {
options;
/**
* Returns a new instance of a FeedbackModal action set
* @param app the client application
*/
constructor(app, options) {
super(app, Group.FeedbackModal, Group.FeedbackModal);
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.OPEN: {
const openAction = open(this.payload);
this.app.dispatch(openAction);
break;
}
case Action.CLOSE: {
const closeAction = close(this.payload);
this.app.dispatch(closeAction);
break;
}
}
return this;
}
}
/**
* Returns a new instance of a FeedbackModal action set
* @param app the client application
*/
function create(app, options) {
return new FeedbackModal(app, options);
}
export { Action, FeedbackModal, close, create, open };