UNPKG

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