UNPKG

5.33 kBTypeScriptView Raw
1import { Store, StoreEnhancer } from 'redux';
2
3//
4// Decorators
5//
6
7/**
8 * Class decorator.
9 */
10export function component(ctor: Function): any;
11export function component(options: SchemaOptions): any;
12
13/**
14 * Property decorator.
15 *
16 * Computed values are computed each time the store state is changed.
17 */
18export function computed(target: any, propertyKey: string | symbol): void;
19
20export class ConnectOptions {
21 /**
22 * The name of the ReduxApp instance to connect to.
23 * If not specified will connect to default app.
24 */
25 app?: string;
26 /**
27 * The ID of the target component (assuming the ID was assigned to the
28 * component by the 'withId' decorator).
29 * If not specified will connect to the first available component of that type.
30 */
31 id?: any;
32 /**
33 * The 'connect' decorator uses a getter to connect to the it's target. By
34 * default the getter is replaced with a standard value (reference) once the
35 * first non-empty value is retrieved. Set this value to true to leave the
36 * getter in place.
37 * Default value: false
38 */
39 live?: boolean;
40}
41
42/**
43 * Property decorator.
44 *
45 * Connects the property to a component in the specified (or default) app.
46 *
47 * Usage Note:
48 *
49 * Connected properties can be thought of as pointers to other components. If
50 * the connected property has an initial value assigned, it will be overridden
51 * once the component is connected. One consequence of this fact is that there
52 * must be at least one source component, i.e. there must be at least one
53 * component of that type that has a value and is not decorated with the
54 * 'connect' decorator.
55 */
56export function connect(options?: ConnectOptions): PropertyDecorator;
57export function connect(target: any, propertyKey: string | symbol): void;
58
59/**
60 * Method decorator.
61 *
62 * Instruct redux-app to keep this method as is and not to replace it with invocation of store.dispatch.
63 * Alias of 'sequence'.
64 */
65export function noDispatch(target: any, propertyKey: string | symbol): void;
66/**
67 * Method decorator.
68 *
69 * Instruct redux-app to keep this method as is and not to replace it with invocation of store.dispatch.
70 * Alias of 'noDispatch'.
71 */
72export function sequence(target: any, propertyKey: string | symbol): void;
73
74/**
75 * Property decorator.
76 */
77export function withId(target: object, propertyKey: string | symbol): void;
78export function withId(id?: any): PropertyDecorator;
79
80
81//
82// ReduxApp
83//
84
85export class ReduxApp<T extends object> {
86
87 /**
88 * Global redux-app options.
89 */
90 static options: GlobalOptions;
91
92 static createApp<T extends object>(appCreator: T, enhancer?: StoreEnhancer<T>): ReduxApp<T>;
93 static createApp<T extends object>(appCreator: T, options: AppOptions, enhancer?: StoreEnhancer<T>): ReduxApp<T>;
94 static createApp<T extends object>(appCreator: T, options: AppOptions, preloadedState: any, enhancer?: StoreEnhancer<T>): ReduxApp<T>;
95
96 readonly name: string;
97 /**
98 * The root component of the application.
99 */
100 readonly root: T;
101 /**
102 * The underlying redux store.
103 */
104 readonly store: Store<T>;
105
106 constructor(appCreator: T, enhancer?: StoreEnhancer<T>);
107 constructor(appCreator: T, options: AppOptions, enhancer?: StoreEnhancer<T>);
108 constructor(appCreator: T, options: AppOptions, preloadedState: any, enhancer?: StoreEnhancer<T>);
109
110 dispose(): void;
111}
112
113//
114// Utilities
115//
116
117export function isInstanceOf(obj: any, type: Function): boolean;
118
119//
120// Options
121//
122
123export class SchemaOptions {
124 /**
125 * Add the class name of the object that holds the action to the action name.
126 * Format: <class name>.<action name>
127 * Default value: true.
128 */
129 actionNamespace?: boolean;
130 /**
131 * Use redux style action names. For instance, if a component defines a
132 * method called 'incrementCounter' the matching action name will be
133 * 'INCREMENT_COUNTER'.
134 * Default value: true.
135 */
136 uppercaseActions?: boolean;
137}
138
139export class AppOptions {
140 /**
141 * Name of the newly created app.
142 */
143 name?: string;
144 /**
145 * By default each component is assigned (with some optimizations) with it's
146 * relevant sub state on each store change. Set this to false to disable
147 * this updating process. The store's state will still be updated as usual
148 * and can always be retrieved using store.getState().
149 * Default value: true.
150 */
151 updateState?: boolean;
152}
153
154export class GlobalOptions {
155 /**
156 * Default value: LogLevel.Warn
157 */
158 logLevel: LogLevel;
159 /**
160 * When set to 'true' every component will have an additional __originalClassName__ property.
161 * May be useful for debugging.
162 * Default value: false.
163 */
164 emitClassNames: boolean;
165 /**
166 * Global defaults.
167 * Options supplied explicitly via the decorator will override options specified here.
168 */
169 schema: SchemaOptions;
170}
171
172export enum LogLevel {
173 /**
174 * Emit no logs
175 */
176 None = 0,
177 Verbose = 1,
178 Debug = 2,
179 Warn = 5,
180 /**
181 * Emit no logs (same as None)
182 */
183 Silent = 10
184}
\No newline at end of file