@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
57 lines (54 loc) • 2.77 kB
JavaScript
import { __assign } from 'tslib';
import { unstable_Picker } from '@shopify/app-bridge-core/actions';
import { validateAction } from '@shopify/app-bridge-core/validate/actions/picker';
var defaultPickerStore = null;
function pickerReducer(state, action) {
if (state === void 0) { state = defaultPickerStore; }
var castAction = action;
if (validateAction(castAction)) {
return state;
}
switch (action.type) {
case unstable_Picker.Action.OPEN:
case unstable_Picker.Action.UPDATE: {
var open_1 = action.type === unstable_Picker.Action.OPEN ? true : (state && state.open) || false;
var _a = castAction.payload, id = _a.id, selectedItems = _a.selectedItems, maxSelectable = _a.maxSelectable, items = _a.items, title = _a.title, loading = _a.loading, searchQueryPlaceholder = _a.searchQueryPlaceholder, searchQuery = _a.searchQuery, primaryActionLabel = _a.primaryActionLabel, secondaryActionLabel = _a.secondaryActionLabel, emptySearchLabel = _a.emptySearchLabel, canLoadMore = _a.canLoadMore, loadingMore = _a.loadingMore, verticalAlignment = _a.verticalAlignment, allowEmptySelection = _a.allowEmptySelection, resourceName = _a.resourceName;
return {
id: id,
items: items,
selectedItems: selectedItems,
maxSelectable: maxSelectable,
open: open_1,
title: title,
loading: loading,
searchQueryPlaceholder: searchQueryPlaceholder,
searchQuery: searchQuery,
primaryActionLabel: primaryActionLabel,
secondaryActionLabel: secondaryActionLabel,
emptySearchLabel: emptySearchLabel,
canLoadMore: canLoadMore,
loadingMore: loadingMore,
verticalAlignment: verticalAlignment,
allowEmptySelection: allowEmptySelection,
resourceName: resourceName,
};
}
case unstable_Picker.Action.SELECT: {
var selectedItems = castAction.payload.selectedItems;
return __assign(__assign({}, state), { selectedItems: selectedItems, open: false });
}
case unstable_Picker.Action.CANCEL: {
return __assign(__assign({}, state), { open: false });
}
case unstable_Picker.Action.SEARCH: {
var searchQuery = castAction.payload.searchQuery;
return __assign(__assign({}, state), { loading: true, searchQuery: searchQuery });
}
case unstable_Picker.Action.LOAD_MORE: {
return __assign({}, state);
}
default:
return state;
}
}
export { pickerReducer as default, defaultPickerStore };