UNPKG

4.54 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}
50/**
51 * The app state keyed with `appBridge`
52 * @internal
53 */
54export interface AppBridgeStore {
55 appBridge: Store;
56}
57/**
58 * The interface for an injected reducer's options
59 * @public
60 * */
61export interface ReducerMap<State> {
62 /** A key matching a property in the app state */
63 key: keyof Store;
64 /** Reducer to add to a store */
65 reducer: Reducer<State>;
66 /** Optional default state for the injected reducer*/
67 initialState?: Partial<State>;
68}
69/**
70 * The constant key `appBridge`
71 * @public
72 */
73export declare const APP_BRIDGE_KEY = "appBridge";
74/**
75 * Returns a combined reducer for the `appBridge` key
76 * Always includes the `features` reducer
77 * @public
78 * @param stateReducers - a reducer map for the dynamic app state
79 * @param initialState - an optional default value for the store
80 */
81export declare function createReducers(stateReducers?: ReducersMapObject, initialState?: Partial<Store>): (state: {
82 [APP_BRIDGE_KEY]: {
83 features: {};
84 };
85} | undefined, action: AnyAction) => AppBridgeStore;
86/**
87 * Creates a store containing only the default `features` reducer
88 * @public
89 */
90export declare function createStore(middleware?: Array<ReturnType<typeof buildMiddleware> | ReduxMiddleware>, initialState?: Partial<Store>, debug?: boolean): ReduxStore<AppBridgeStore, AnyAction> & {
91 dispatch: {};
92};
93/**
94 * Creates a method that when called, dynamically adds a reducer to
95 * the provided store
96 * @internal
97 * @param store - a Redux store
98 * @param globalInitialState - custom overrides for resolving the app state when adding a new reducer
99 * */
100export declare function createAddReducer(store: ReduxStore, globalInitialState?: Partial<Store>): <State>({ key, reducer, initialState }: ReducerMap<State>) => void;
101declare type QueuedClientAction = MetaAction & {
102 group: Group;
103};
104/**
105 * The inteface for a queue with methods to add to the queue, clear the queue and also resolve the queue
106 * @internal
107 * */
108export interface ActionsQueue {
109 /** Add the action to the queue for the provided `context` */
110 add(context: Context, action: QueuedClientAction): void;
111 /** Removes all actions in the queue for the provided `context` */
112 clear(context: Context): void;
113 /** Dispatch all actions related to the feature in the queue for all contexts */
114 resolve(key: HostFeatures): void;
115}
116/**
117 * Creates an action queue for the provided store
118 * @internal
119 * */
120export declare function createActionsQueue(store: MiddlewareAPI<any>): ActionsQueue;
121/**
122 * Predicate to determine if a reducer for the associated action is already loaded
123 * @internal
124 */
125export declare function isReducerLoaded(state: any, action: any): any;
126export {};