UNPKG

4.44 kBTypeScriptView Raw
1import { Store, StoreEnhancer } from 'redux';
2
3//
4// Decorators
5//
6
7/**
8 * Method decorator.
9 *
10 * Mark this method as a Redux action.
11 */
12export function action(target: object, propertyKey: string | symbol): void;
13
14/**
15 * Method decorator.
16 *
17 * The method will dispatch an action with the corresponding name but the
18 * dispatched action will **not** trigger a reducer reaction. Instead, after the
19 * dispatch process is done the method will be invoked as a regular one
20 * (similarly to `noDispatch` methods).
21 */
22export function sequence(target: any, propertyKey: string | symbol): void;
23
24/**
25 * Property decorator.
26 */
27export function withId(target: object, propertyKey: string | symbol): void;
28export function withId(id?: any): PropertyDecorator;
29
30/**
31 * Property decorator.
32 * Instruct redux-app to not store this property in the store.
33 */
34export function ignoreState(target: object, propertyKey: string | symbol): void;
35
36//
37// ReduxApp
38//
39
40export class ReduxApp<T extends object> {
41
42 /**
43 * Global redux-app options.
44 */
45 static options: GlobalOptions;
46
47 static createApp<T extends object>(appCreator: T, enhancer?: StoreEnhancer<T>): ReduxApp<T>;
48 static createApp<T extends object>(appCreator: T, options: AppOptions, enhancer?: StoreEnhancer<T>): ReduxApp<T>;
49 static createApp<T extends object>(appCreator: T, options: AppOptions, preloadedState: any, enhancer?: StoreEnhancer<T>): ReduxApp<T>;
50
51 /**
52 * @param type The type of the component.
53 * @param componentId The ID of the component (assuming the ID was assigned
54 * to the component by the 'withId' decorator). If not specified will get to
55 * the first available component of that type.
56 * @param appId The name of the ReduxApp instance to search in. If not
57 * specified will search in default app.
58 */
59 static getComponent<T>(type: Constructor<T>, componentId?: string, appId?: string): T;
60
61 readonly name: string;
62 /**
63 * The root component of the application.
64 */
65 readonly root: T;
66 /**
67 * The underlying redux store.
68 */
69 readonly store: Store<T>;
70
71 constructor(appCreator: T, enhancer?: StoreEnhancer<T>);
72 constructor(appCreator: T, options: AppOptions, enhancer?: StoreEnhancer<T>);
73 constructor(appCreator: T, options: AppOptions, preloadedState: any, enhancer?: StoreEnhancer<T>);
74
75 dispose(): void;
76}
77
78//
79// Utilities
80//
81
82export function isInstanceOf(obj: any, type: Function): boolean;
83
84/**
85 * @param obj
86 * @param bind Whether or not to bind the returned methods to 'obj'. Default
87 * value: false.
88 */
89export function getMethods(obj: object | Function, bind?: boolean): IMap<Method>;
90
91//
92// types
93//
94
95export type Method = Function;
96
97export interface Constructor<T> {
98 new(...args: any[]): T;
99}
100
101export interface IMap<T> {
102 [key: string]: T;
103}
104
105//
106// Options
107//
108
109export class ActionOptions {
110 /**
111 * Add the class name of the object that holds the action to the action name.
112 * Format: <class name><separator><action name>
113 * Default value: true.
114 */
115 actionNamespace?: boolean;
116 /**
117 * Default value: . (dot)
118 */
119 actionNamespaceSeparator?: string;
120 /**
121 * Use redux style action names. For instance, if a component defines a
122 * method called 'incrementCounter' the matching action name will be
123 * 'INCREMENT_COUNTER'.
124 * Default value: false.
125 */
126 uppercaseActions?: boolean;
127}
128
129export class AppOptions {
130 /**
131 * Name of the newly created app.
132 */
133 name?: string;
134 /**
135 * By default each component is assigned (with some optimizations) with it's
136 * relevant sub state on each store change. Set this to false to disable
137 * this updating process. The store's state will still be updated as usual
138 * and can always be retrieved using store.getState().
139 * Default value: true.
140 */
141 updateState?: boolean;
142}
143
144export class GlobalOptions {
145 /**
146 * Default value: LogLevel.Warn
147 */
148 logLevel: LogLevel;
149 /**
150 * Customize actions naming.
151 */
152 action: ActionOptions;
153}
154
155export enum LogLevel {
156 /**
157 * Emit no logs
158 */
159 None = 0,
160 Verbose = 1,
161 Debug = 2,
162 Warn = 5,
163 /**
164 * Emit no logs (same as None)
165 */
166 Silent = 10
167}
\No newline at end of file