@@ -19,8 +19,8 @@ Set of guidelines and patterns teaching how to fully leverage TypeScript feature
19
19
- [ Actions] ( #actions )
20
20
- [ Reducers] ( #reducers )
21
21
- [ Async Flow] ( #async-flow )
22
+ - [ Reselect Selectors] ( #reselect-selectors )
22
23
- [ Store & RootState] ( #store--rootstate )
23
- - [ Types Selectors] ( #typed-selectors )
24
24
- [ Common] ( #common )
25
25
- [ Vendor Types Augumentation] ( #vendor-types-augmentation )
26
26
- [ FAQ] ( #faq )
@@ -33,6 +33,8 @@ Set of guidelines and patterns teaching how to fully leverage TypeScript feature
33
33
- Don't use constructor - use Property Initializers
34
34
- Don't use instance methods and bind - use Class Fields with arrow functions
35
35
36
+ ---
37
+
36
38
## Class Component
37
39
- class component boilerplate
38
40
``` tsx
@@ -84,8 +86,11 @@ class MyComponent extends React.Component<Props, State> {
84
86
};
85
87
86
88
export default MyComponent ;
89
+
87
90
```
88
91
92
+ ---
93
+
89
94
## Stateless Component
90
95
- stateless component boilerplate
91
96
``` tsx
@@ -109,8 +114,11 @@ const MyComponent: React.StatelessComponent<Props> = (props) => {
109
114
};
110
115
111
116
export default MyComponent ;
117
+
112
118
```
113
119
120
+ ---
121
+
114
122
## Higher-Order Component
115
123
- decorate or wraps a component into another component
116
124
- using Type Inference to automatically calculate Props interface for the resulting component
@@ -142,6 +150,7 @@ const ButtonControl: React.StatelessComponent<Props> = (props) => {
142
150
};
143
151
144
152
export default ButtonControl ;
153
+
145
154
```
146
155
147
156
``` tsx
@@ -193,8 +202,11 @@ const ButtonWithFormItem = withFormItemDecorator(Button);
193
202
Next Step
194
203
</ButtonWithFormItem >
195
204
...
205
+
196
206
```
197
207
208
+ ---
209
+
198
210
## Redux Connected Component
199
211
- This solution uses type inference to get Props types from ` mapStateToProps ` function
200
212
- Minimise manual effort to declare and maintain Props types injected from ` connect ` helper function
@@ -259,12 +271,16 @@ class CurrencyConverterContainer extends React.Component<Props, State> {
259
271
}
260
272
261
273
export default connect (mapStateToProps , dispatchToProps )(CurrencyConverterContainer );
274
+
262
275
```
263
276
277
+
264
278
---
265
279
266
280
# Redux
267
281
282
+ ---
283
+
268
284
## Actions
269
285
270
286
### KISS Approach
@@ -311,6 +327,7 @@ export default function reducer(state: State = initialState, action: Action): St
311
327
state .baseCurrency = action .payload // string
312
328
break ;
313
329
...
330
+
314
331
` ` `
315
332
316
333
### DRY Approach
@@ -346,6 +363,7 @@ export default function reducer(state: State = initialState, action: Action): St
346
363
state .baseCurrency = action .payload ; // string
347
364
}
348
365
...
366
+
349
367
` ` `
350
368
351
369
---
@@ -383,6 +401,7 @@ export default function reducer(state: State = initialState, action: Action): St
383
401
default : return state ;
384
402
}
385
403
}
404
+
386
405
` ` `
387
406
388
407
### If Approach
@@ -412,6 +431,7 @@ export default function reducer(state: State = initialState, action: Action): St
412
431
413
432
return partialState != null ? { ... state , ... partialState } : state ;
414
433
}
434
+
415
435
` ` `
416
436
417
437
---
@@ -425,6 +445,15 @@ export default function reducer(state: State = initialState, action: Action): St
425
445
426
446
---
427
447
448
+ ## Reselect Selectors
449
+ - WIP
450
+
451
+ ` ` ` ts
452
+
453
+ ` ` `
454
+
455
+ ---
456
+
428
457
## Store & RootState
429
458
430
459
` RootState ` - to be imported in connected components providing type safety to Redux ` connect ` function
@@ -440,6 +469,7 @@ export type RootState = {
440
469
currencyRates: CurrencyRatesState ;
441
470
currencyConverter: CurrencyConverterState ;
442
471
};
472
+
443
473
` ` `
444
474
445
475
Use ` RootState ` in ` combineReducers ` function and as rehydrated State object type guard to obtain strongly typed Store instance
@@ -458,12 +488,8 @@ export const store = createStore(
458
488
rootReducer ,
459
489
recoverState (),
460
490
);
461
- ` ` `
462
-
463
- ---
464
491
465
- ## Typed Selectors
466
- - WIP
492
+ ` ` `
467
493
468
494
---
469
495
@@ -484,6 +510,7 @@ declare module '../node_modules/antd/lib/button/Button' {
484
510
autoFocus? : boolean ;
485
511
}
486
512
}
513
+
487
514
` ` `
488
515
489
516
---
@@ -517,6 +544,7 @@ import { Select } from '../components';
517
544
or
518
545
import Select from ' ../components/select' ;
519
546
...
547
+
520
548
` ` `
521
549
522
550
---
0 commit comments