UNPKG

5.04 kBTypeScriptView Raw
1import { compose, Middleware as ReduxMiddleware, MiddlewareAPI, ReducersMapObject, Reducer, Store as ReduxStore, AnyAction } from 'redux';
2import { Context } from '@shopify/app-bridge';
3import { MetaAction, Group } from '@shopify/app-bridge/actions';
4import { buildMiddleware } from '../Middleware';
5import { HostFeatures } from '../types';
6import { PerformanceStore } from '../features/performance';
7import { FeaturesState } from './reducers/embeddedApp/features';
8import { ToastStore } from './reducers/embeddedApp/toast';
9import { LoadingStore } from './reducers/embeddedApp/loading';
10import { ModalStore } from './reducers/embeddedApp/modal';
11import { TitleBarStore } from './reducers/embeddedApp/titleBar';
12import { ResourcePickerStore } from './reducers/embeddedApp/resourcePicker';
13import { NavigationStore } from './reducers/embeddedApp/navigation';
14import { POSStore } from './reducers/embeddedApp/pos';
15import { StaffMemberStore } from './reducers/embeddedApp/staffMember';
16import { ContextualSaveBarStore } from './reducers/embeddedApp/contextualSaveBar';
17import { MenuStore } from './reducers/embeddedApp/menu';
18import { Store as FeedbackModalStore } from './reducers/feedbackModal';
19import { Store as LeaveConfirmationStore } from './reducers/leaveConfirmation';
20interface DevToolsOptions {
21 name?: string;
22 shouldHotReload?: boolean;
23}
24declare global {
25 interface Window {
26 __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: (options: DevToolsOptions) => typeof compose;
27 }
28}
29/**
30 * The interface for the app state
31 * @public
32 */
33export interface Store {
34 features: FeaturesState;
35 performance?: PerformanceStore;
36 pos?: POSStore;
37 staffMember?: StaffMemberStore;
38 isLegacy?: boolean;
39 contextualSaveBar?: ContextualSaveBarStore;
40 fullscreen?: boolean;
41 loading?: LoadingStore;
42 modal?: ModalStore;
43 navigation?: NavigationStore;
44 resourcePicker?: ResourcePickerStore | null;
45 titleBar?: TitleBarStore | null;
46 toast?: ToastStore;
47 menu?: MenuStore;
48 scanner?: {};
49 print?: {};
50 share?: {};
51 cart?: {};
52 sessionToken?: {};
53 authCode?: {};
54 marketingExternalActivityTopBar?: {};
55 feedbackModal?: FeedbackModalStore;
56 leaveConfirmation?: LeaveConfirmationStore;
57}
58/**
59 * The app state keyed with `appBridge`
60 * @internal
61 */
62export interface AppBridgeStore {
63 appBridge: Store;
64}
65/**
66 * The interface for an injected reducer's options
67 * @public
68 * */
69export interface ReducerMap<State> {
70 /** A key matching a property in the app state */
71 key: keyof Store;
72 /** Reducer to add to a store */
73 reducer: Reducer<State>;
74 /** Optional default state for the injected reducer*/
75 initialState?: Partial<State>;
76}
77/**
78 * The constant key `appBridge`
79 * @public
80 */
81export declare const APP_BRIDGE_KEY = "appBridge";
82/**
83 * Returns a combined reducer for the `appBridge` key
84 * Always includes the `features` reducer
85 * @public
86 * @param stateReducers - a reducer map for the dynamic app state
87 * @param initialState - an optional default value for the store
88 */
89export declare function createReducers(stateReducers?: ReducersMapObject, initialState?: Partial<Store>): (state: {
90 appBridge: {
91 features: {};
92 };
93} | undefined, action: AnyAction) => AppBridgeStore | {
94 appBridge: {
95 features: {};
96 };
97};
98/**
99 * Creates a store containing only the default `features` reducer
100 * @public
101 */
102export declare function createStore(middleware?: Array<ReturnType<typeof buildMiddleware> | ReduxMiddleware>, initialState?: Partial<Store>, debug?: boolean): ReduxStore<AppBridgeStore | {
103 appBridge: {
104 features: {};
105 };
106}, AnyAction> & {
107 dispatch: unknown;
108};
109/**
110 * Creates a method that when called, dynamically adds a reducer to
111 * the provided store
112 * @internal
113 * @param store - a Redux store
114 * @param globalInitialState - custom overrides for resolving the app state when adding a new reducer
115 * */
116export declare function createAddReducer(store: ReduxStore, globalInitialState?: Partial<Store>): <State>({ key, reducer, initialState }: ReducerMap<State>) => void;
117declare type QueuedClientAction = MetaAction & {
118 group: Group;
119};
120/**
121 * The inteface for a queue with methods to add to the queue, clear the queue and also resolve the queue
122 * @internal
123 * */
124export interface ActionsQueue {
125 /** Add the action to the queue for the provided `context` */
126 add(context: Context, action: QueuedClientAction): void;
127 /** Removes all actions in the queue for the provided `context` */
128 clear(context: Context): void;
129 /** Dispatch all actions related to the feature in the queue for all contexts */
130 resolve(key: HostFeatures): void;
131}
132/**
133 * Creates an action queue for the provided store
134 * @internal
135 * */
136export declare function createActionsQueue(store: MiddlewareAPI<any>): ActionsQueue;
137/**
138 * Predicate to determine if a reducer for the associated action is already loaded
139 * @internal
140 */
141export declare function isReducerLoaded(state: any, action: any): boolean;
142export {};