UNPKG

@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

43 lines (40 loc) 1.73 kB
import { Action } from '@shopify/app-bridge-core/actions/Toast'; import { retain } from '@remote-ui/core'; import { resetStateReducer } from '../utilities.js'; import { toastActionCreatorsMap } from './actionCreators.js'; import toastReducer, { defaultToastStore } from './reducer.js'; export { LegacyFlashClear, LegacyFlashShow } from './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; retain(onAction); actions.show(payload); // Remove old subscription and stores new one unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe(); unsubscribe = subscribe(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: toastActionCreatorsMap, key: 'toast', initialState: defaultToastStore, reducer: resetStateReducer(toastReducer), getApi: getApi, }; export { toastReducer as default, defaultToastStore, feature, toastActionCreatorsMap };