@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
52 lines (47 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var Toast = require('@shopify/app-bridge-core/actions/Toast');
var core = require('@remote-ui/core');
var utilities = require('../utilities.js');
var actionCreators = require('./actionCreators.js');
var store_reducers_embeddedApp_toast_reducer = require('./reducer.js');
var types = require('./types.js');
var getApi = function (_a) {
var actions = _a.actions, subscribe = _a.subscribe;
// [TODO] revisit unsubscribe implementation to make sure we unsubscribe even if the use navigates away.
var unsubscribe = null;
var api = {
show: function (payload) {
var _a;
var onAction = (_a = payload.action) === null || _a === void 0 ? void 0 : _a.onAction;
core.retain(onAction);
actions.show(payload);
// Remove old subscription and stores new one
unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
unsubscribe = subscribe(Toast.Action.ACTION, function () { return onAction === null || onAction === void 0 ? void 0 : onAction(); });
},
clear: function (payload) {
actions.clear(payload);
},
};
return api;
};
/**
* An object containing the key, actions, initial state and reducer of the Loading feature
* Can be used with the `withFeature` decorator to add the reducer
* and then make its actions and store available to the wrapped component
* @public
* */
var feature = {
actions: actionCreators.toastActionCreatorsMap,
key: 'toast',
initialState: store_reducers_embeddedApp_toast_reducer.defaultToastStore,
reducer: utilities.resetStateReducer(store_reducers_embeddedApp_toast_reducer.default),
getApi: getApi,
};
exports.toastActionCreatorsMap = actionCreators.toastActionCreatorsMap;
exports.default = store_reducers_embeddedApp_toast_reducer.default;
exports.defaultToastStore = store_reducers_embeddedApp_toast_reducer.defaultToastStore;
exports.LegacyFlashClear = types.LegacyFlashClear;
exports.LegacyFlashShow = types.LegacyFlashShow;
exports.feature = feature;