@shopify/app-bridge-core
Version:
**[Join our team and work on libraries like this one.](https://www.shopify.ca/careers)**
81 lines (78 loc) • 2.3 kB
JavaScript
import { getMergedProps, actionWrapper } from '../helper.js';
import { ActionSet } from '../ActionSet.js';
import { Group } from '../types.js';
/**
* ContextualSaveBar action enum
*/
var Action;
(function (Action) {
Action["DISCARD"] = "APP::CONTEXTUAL_SAVE_BAR::DISCARD";
Action["SAVE"] = "APP::CONTEXTUAL_SAVE_BAR::SAVE";
Action["SHOW"] = "APP::CONTEXTUAL_SAVE_BAR::SHOW";
Action["HIDE"] = "APP::CONTEXTUAL_SAVE_BAR::HIDE";
Action["UPDATE"] = "APP::CONTEXTUAL_SAVE_BAR::UPDATE";
})(Action || (Action = {}));
function createContextBarAction(action, payload) {
return actionWrapper({
group: Group.ContextualSaveBar,
type: action,
payload,
});
}
function show(payload) {
return createContextBarAction(Action.SHOW, payload);
}
function hide(payload) {
return createContextBarAction(Action.HIDE, payload);
}
function save(payload) {
return createContextBarAction(Action.SAVE, payload);
}
function discard(payload) {
return createContextBarAction(Action.DISCARD, payload);
}
function update(payload) {
return createContextBarAction(Action.UPDATE, payload);
}
/**
* ContextualSaveBar action set
*/
class ContextualSaveBar extends ActionSet {
options;
/**
* Returns a new instance of a ContextualSaveBar action set
* @param app the client application
*/
constructor(app, options = {}) {
super(app, Group.ContextualSaveBar, Group.ContextualSaveBar);
this.options = options;
this.set(options, false);
}
/**
* Returns the action set payload
*/
get payload() {
return {
id: this.id,
...this.options,
};
}
set(options, shouldUpdate = true) {
const mergedOptions = getMergedProps(this.options, options);
this.options = mergedOptions;
if (shouldUpdate) {
this.dispatch(Action.UPDATE);
}
return this;
}
/**
* Dispatches a given action with the action set payload
* @param action the action enum
* @returns the action set instance
*/
dispatch(action) {
this.app.dispatch(createContextBarAction(action, this.payload));
return this;
}
}
export { Action, ContextualSaveBar, discard, hide, save, show, update };