UNPKG

3.76 kBTypeScriptView Raw
1import { ClientApplication } from '../client';
2import { ActionSet } from './helper';
3import { ErrorAction } from './Error/actions';
4/**
5 * Various action groups.
6 * @public
7 */
8export declare enum Group {
9 AuthCode = "AuthCode",
10 Button = "Button",
11 ButtonGroup = "ButtonGroup",
12 Cart = "Cart",
13 ContextualSaveBar = "ContextualSaveBar",
14 Error = "Error",
15 Features = "Features",
16 Fullscreen = "Fullscreen",
17 Link = "Link",
18 Loading = "Loading",
19 Menu = "Menu",
20 Modal = "Modal",
21 Navigation = "Navigation",
22 Pos = "Pos",
23 Print = "Print",
24 ResourcePicker = "Resource_Picker",
25 Scanner = "Scanner",
26 SessionToken = "SessionToken",
27 Share = "Share",
28 TitleBar = "TitleBar",
29 Toast = "Toast"
30}
31/**
32 * @internal
33 */
34export declare enum ComponentType {
35 Button = "Button",
36 ButtonGroup = "ButtonGroup"
37}
38/**
39 * Base action interface.
40 * @remarks
41 * All action implementations should inherit from this interface.
42 * @internalremarks
43 * Should we remove the extraProps definition here, pushing it on sub-types?
44 * @public
45 */
46export interface AnyAction {
47 type: any;
48 [extraProps: string]: any;
49}
50export interface ClientInterface {
51 name?: string;
52 version?: string;
53}
54/**
55 * @public
56 */
57export interface MetaAction extends AnyAction {
58 clientInterface?: ClientInterface;
59 readonly version: string;
60 readonly group: string;
61 readonly type: string;
62 payload?: any;
63}
64/**
65 * @public
66 */
67export interface ClickAction extends MetaAction {
68 payload: {
69 id: string;
70 payload?: any;
71 };
72}
73/**
74 * @public
75 */
76export interface ActionCallback {
77 (data: any): void;
78}
79/**
80 * @public
81 */
82export interface ErrorCallback {
83 (data: ErrorAction): void;
84}
85/**
86 * @public
87 */
88export interface UpdateSubscribe {
89 (group: string, subgroups: string[]): void;
90}
91/**
92 * @public
93 */
94export interface Unsubscribe {
95 (): void;
96}
97/**
98 * @public
99 */
100export interface ErrorSubscriber {
101 (callback: ErrorCallback): Unsubscribe;
102}
103/**
104 * @internal
105 */
106export interface ActionSubscription {
107 component: Component;
108 eventType: string;
109 callback: ActionCallback;
110 unsubscribe: Unsubscribe;
111 updateSubscribe: UpdateSubscribe;
112}
113/**
114 * @internal
115 */
116export interface UpdateSubscription {
117 (subscriptionToRemove: ActionSubscription, group: string, subgroups: string[]): void;
118}
119/**
120 * @public
121 */
122export interface Component {
123 readonly id: string;
124 readonly type: string;
125 subgroups?: string[];
126}
127/**
128 * @public
129 */
130export interface ActionSetInterface extends Component {
131 readonly app: ClientApplication<any>;
132 readonly defaultGroup: string;
133 group: string;
134 component: Component;
135 subscriptions: ActionSubscription[];
136 updateSubscription: UpdateSubscription;
137 error: ErrorSubscriber;
138 subscribe(eventName: string, callback: ActionCallback, component?: Component, currentIndex?: number): Unsubscribe;
139 unsubscribe(resetOnly: boolean): ActionSetInterface;
140}
141/**
142 * @public
143 */
144export interface DispatchAction {
145 type: string;
146 payload: any;
147}
148/**
149 * @public
150 */
151export interface SimpleDispatch {
152 dispatch(action: string): ActionSet;
153}
154/**
155 * @public
156 */
157export interface ComplexDispatch<P> {
158 dispatch(action: string, payload: P): ActionSet;
159}
160/**
161 * @public
162 */
163export interface ActionSetProps<T, P> extends SimpleDispatch {
164 options: T;
165 payload: P;
166 set(options: Partial<T>): ActionSet;
167}
168/**
169 * @public
170 */
171export interface ActionSetPayload<P> extends SimpleDispatch {
172 payload: P;
173}
174/**
175 * @public
176 */
177export interface ActionSetOptions<T> {
178 options: T;
179 set(options: Partial<T>): ActionSet;
180}
181/**
182 * @public
183 */
184export interface Dispatch<_> {
185 <A extends AnyAction>(action: A): A;
186}