@@ -60,7 +60,6 @@ You should check Playground Project located in the `/playground` folder. It is a
60
60
- [ Vendor Types Augmentation] ( #vendor-types-augmentation )
61
61
- [ Default and Named Module Exports] ( #default-and-named-module-exports )
62
62
- [ FAQ] ( #faq )
63
- - [ Contribution Guide] ( #contribution-guide )
64
63
- [ Tutorials] ( #tutorials )
65
64
66
65
---
@@ -505,8 +504,8 @@ export const withState = <WrappedProps extends InjectedProps>(
505
504
` ` ` tsx
506
505
import * as React from ' react' ;
507
506
508
- import { withState } from ' @src /hoc' ;
509
- import { SFCCounter } from ' @src /components' ;
507
+ import { withState } from ' .. /hoc' ;
508
+ import { SFCCounter } from ' .. /components' ;
510
509
511
510
const SFCCounterWithState =
512
511
withState (SFCCounter );
@@ -589,8 +588,8 @@ export const withErrorBoundary = <WrappedProps extends InjectedProps>(
589
588
` ` ` tsx
590
589
import * as React from ' react' ;
591
590
592
- import { withErrorBoundary } from ' @src /hoc' ;
593
- import { ErrorMessage } from ' @src /components' ;
591
+ import { withErrorBoundary } from ' .. /hoc' ;
592
+ import { ErrorMessage } from ' .. /components' ;
594
593
595
594
const ErrorMessageWithErrorBoundary =
596
595
withErrorBoundary (ErrorMessage );
@@ -633,14 +632,14 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
633
632
#### - redux connected counter
634
633
635
634
` ` ` tsx
635
+ import Types from ' Types' ;
636
636
import { connect } from ' react-redux' ;
637
637
638
- import { RootState } from ' @src/redux' ;
639
- import { countersActions , countersSelectors } from ' @src/redux/counters' ;
640
- import { SFCCounter } from ' @src/components' ;
638
+ import { countersActions , countersSelectors } from ' ../features/counters' ;
639
+ import { SFCCounter } from ' ../components' ;
641
640
642
- const mapStateToProps = (state : RootState ) => ({
643
- count: countersSelectors .getReduxCounter (state ),
641
+ const mapStateToProps = (state : Types . RootState ) => ({
642
+ count: countersSelectors .getReduxCounter (state . counters ),
644
643
});
645
644
646
645
export const SFCCounterConnected = connect (mapStateToProps , {
@@ -653,7 +652,7 @@ export const SFCCounterConnected = connect(mapStateToProps, {
653
652
` ` ` tsx
654
653
import * as React from ' react' ;
655
654
656
- import { SFCCounterConnected } from ' @src /connected' ;
655
+ import { SFCCounterConnected } from ' .. /connected' ;
657
656
658
657
export default () => (
659
658
<SFCCounterConnected
@@ -669,14 +668,14 @@ export default () => (
669
668
#### - redux connected counter (verbose)
670
669
671
670
` ` ` tsx
672
- import { bindActionCreators } from ' redux' ;
671
+ import Types from ' Types' ;
672
+ import { bindActionCreators , Dispatch } from ' redux' ;
673
673
import { connect } from ' react-redux' ;
674
674
675
- import { RootState , Dispatch } from ' @src/redux' ;
676
- import { countersActions } from ' @src/redux/counters' ;
677
- import { SFCCounter } from ' @src/components' ;
675
+ import { countersActions } from ' ../features/counters' ;
676
+ import { SFCCounter } from ' ../components' ;
678
677
679
- const mapStateToProps = (state : RootState ) => ({
678
+ const mapStateToProps = (state : Types . RootState ) => ({
680
679
count: state .counters .reduxCounter ,
681
680
});
682
681
@@ -693,7 +692,7 @@ export const SFCCounterConnectedVerbose =
693
692
` ` ` tsx
694
693
import * as React from ' react' ;
695
694
696
- import { SFCCounterConnectedVerbose } from ' @src /connected' ;
695
+ import { SFCCounterConnectedVerbose } from ' .. /connected' ;
697
696
698
697
export default () => (
699
698
<SFCCounterConnectedVerbose
@@ -709,18 +708,18 @@ export default () => (
709
708
#### - with own props
710
709
711
710
` ` ` tsx
711
+ import Types from ' Types' ;
712
712
import { connect } from ' react-redux' ;
713
713
714
- import { RootState } from ' @src/redux' ;
715
- import { countersActions , countersSelectors } from ' @src/redux/counters' ;
716
- import { SFCCounter } from ' @src/components' ;
714
+ import { countersActions , countersSelectors } from ' ../features/counters' ;
715
+ import { SFCCounter } from ' ../components' ;
717
716
718
717
export interface SFCCounterConnectedExtendedProps {
719
718
initialCount: number ;
720
719
}
721
720
722
- const mapStateToProps = (state : RootState , ownProps : SFCCounterConnectedExtendedProps ) => ({
723
- count: countersSelectors .getReduxCounter (state ) + ownProps .initialCount ,
721
+ const mapStateToProps = (state : Types . RootState , ownProps : SFCCounterConnectedExtendedProps ) => ({
722
+ count: countersSelectors .getReduxCounter (state . counters ) + ownProps .initialCount ,
724
723
});
725
724
726
725
export const SFCCounterConnectedExtended = connect (mapStateToProps , {
@@ -733,7 +732,7 @@ export const SFCCounterConnectedExtended = connect(mapStateToProps, {
733
732
` ` ` tsx
734
733
import * as React from ' react' ;
735
734
736
- import { SFCCounterConnectedExtended } from ' @src /connected' ;
735
+ import { SFCCounterConnectedExtended } from ' .. /connected' ;
737
736
738
737
export default () => <SFCCounterConnectedExtended label = { ' SFCCounterConnectedExtended' } initialCount = { 10 } />;
739
738
@@ -756,7 +755,7 @@ export default () => <SFCCounterConnectedExtended label={'SFCCounterConnectedExt
756
755
A solution below is using simple factory function to automate the creation of type-safe action creators. The goal is to reduce the maintainability and code repetition of type annotations for actions and creators and the result is completely typesafe action-creators and their actions.
757
756
758
757
` ` ` tsx
759
- import { action , createAction , createStandardAction } from ' typesafe-actions' ;
758
+ import { action } from ' typesafe-actions' ;
760
759
761
760
import { ADD , INCREMENT } from ' ./constants' ;
762
761
@@ -770,10 +769,12 @@ export const add = (amount: number) => action(ADD, amount);
770
769
// https://github.com/piotrwitek/typesafe-actions#behold-the-mighty-tutorial
771
770
772
771
// OPTION 1 (with generics):
772
+ // import { createStandardAction } from 'typesafe-actions';
773
773
// export const increment = createStandardAction(INCREMENT)<void>();
774
774
// export const add = createStandardAction(ADD)<number>();
775
775
776
776
// OPTION 2 (with resolve callback):
777
+ // import { createAction } from 'typesafe-actions';
777
778
// export const increment = createAction(INCREMENT);
778
779
// export const add = createAction(ADD, resolve => {
779
780
// return (amount: number) => resolve(amount);
@@ -869,7 +870,7 @@ state.counterPairs[0].immutableCounter2 = 1; // TS Error: cannot be mutated
869
870
870
871
` ` ` tsx
871
872
import { combineReducers } from ' redux' ;
872
- import { ActionsUnion } from ' typesafe-actions' ;
873
+ import { ActionType } from ' typesafe-actions' ;
873
874
874
875
import { Todo , TodosFilter } from ' ./models' ;
875
876
import * as actions from ' ./actions' ;
@@ -882,7 +883,7 @@ export type TodosState = {
882
883
readonly todosFilter : TodosFilter ;
883
884
};
884
885
885
- export type TodosAction = ActionsUnion < typeof actions > ;
886
+ export type TodosAction = ActionType < typeof actions > ;
886
887
887
888
export default combineReducers <TodosState , TodosAction >({
888
889
isFetching : (state = false , action ) => {
@@ -1010,21 +1011,21 @@ When creating a store instance we don't need to provide any additional types. It
1010
1011
> The resulting store instance methods like ` getState ` or ` dispatch ` will be type checked and will expose all type errors
1011
1012
1012
1013
` ` ` tsx
1013
- import { createStore , applyMiddleware , compose } from ' redux' ;
1014
+ import { createStore , applyMiddleware } from ' redux' ;
1014
1015
import { createEpicMiddleware } from ' redux-observable' ;
1015
1016
1017
+ import { composeEnhancers } from ' ./utils' ;
1016
1018
import rootReducer from ' ./root-reducer' ;
1017
1019
import rootEpic from ' ./root-epic' ;
1020
+ import services from ' ../services' ;
1018
1021
1019
- const composeEnhancers =
1020
- (process .env .NODE_ENV === ' development' &&
1021
- window &&
1022
- window .__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ) ||
1023
- compose ;
1022
+ export const epicMiddleware = createEpicMiddleware (rootEpic , {
1023
+ dependencies: services ,
1024
+ });
1024
1025
1025
1026
function configureStore(initialState ? : object ) {
1026
1027
// configure middlewares
1027
- const middlewares = [createEpicMiddleware ( rootEpic ) ];
1028
+ const middlewares = [epicMiddleware ];
1028
1029
// compose enhancers
1029
1030
const enhancer = composeEnhancers (applyMiddleware (... middlewares ));
1030
1031
// create store
@@ -1048,7 +1049,6 @@ export default store;
1048
1049
### For more examples and in-depth explanation you should read [The Mighty Tutorial](https://github.com/piotrwitek/typesafe-actions#behold-the-mighty-tutorial) to learn it all the easy way!
1049
1050
1050
1051
` ` ` tsx
1051
- // tslint:disable:no-console
1052
1052
import Types from ' Types' ;
1053
1053
import { combineEpics , Epic } from ' redux-observable' ;
1054
1054
import { tap , ignoreElements , filter } from ' rxjs/operators' ;
@@ -1059,12 +1059,13 @@ import { todosConstants, TodosAction } from '../todos';
1059
1059
// contrived example!!!
1060
1060
const logAddAction : Epic < TodosAction , Types.RootState , Types.Services> = (
1061
1061
action$ ,
1062
- store
1062
+ store ,
1063
+ { logger }
1063
1064
) =>
1064
1065
action$.pipe(
1065
1066
filter(isOfType (todosConstants.ADD)), // action is narrowed to: { type: "ADD_TODO"; payload: string; }
1066
1067
tap(action = > {
1067
- console .log(
1068
+ logger .log(
1068
1069
` action type must be equal: ${todosConstants .ADD } === ${action .type } `
1069
1070
);
1070
1071
}),
@@ -1447,33 +1448,16 @@ class StatefulCounter extends React.Component<Props, State> {
1447
1448
1448
1449
---
1449
1450
1450
- # Contribution Guide
1451
- - Don't edit ` README .md ` - it is built with ` generator ` script from separate ` .md ` files located in the ` / docs / markdown ` folder, edit them instead
1452
- - For code snippets, they are also injected by ` generator ` script from the source files located in the playground folder (this step make sure all examples are type-checked and linted), edit them instead
1453
- > look for include directives in ` .md ` files that look like this: ` ::[example | usage ]= ' ../../playground/src/components/sfc-counter.tsx' ::`
1454
-
1455
- Before opening PR please make sure to check:
1456
- ` ` ` bash
1457
- # run linter in playground
1458
- yarn run lint
1459
-
1460
- # run type - checking in playground
1461
- yarn run tsc
1462
-
1463
- # re - generate ` README.md ` from repo root
1464
- sh ./ generate .sh
1465
- # or
1466
- node ./ generator / bin / generate - readme .js
1467
- ` ` `
1468
-
1469
- [⇧ back to top](#table-of-contents)
1470
-
1471
- ---
1472
-
1473
1451
# Tutorials
1474
1452
> Curated list of relevant in-depth tutorials
1475
1453
1476
1454
Higher-Order Components:
1477
1455
- https://medium.com/@jrwebdev/react-higher-order-component-patterns-in-typescript-42278f7590fb
1478
1456
1479
1457
[⇧ back to top](#table-of-contents)
1458
+
1459
+ ---
1460
+
1461
+ MIT License
1462
+
1463
+ Copyright (c) 2017 Piotr Witek <[email protected] > (http://piotrwitek.github.io)
0 commit comments