@@ -60,7 +60,6 @@ You should check Playground Project located in the `/playground` folder. It is a
6060 - [ Vendor Types Augmentation] ( #vendor-types-augmentation )
6161 - [ Default and Named Module Exports] ( #default-and-named-module-exports )
6262- [ FAQ] ( #faq )
63- - [ Contribution Guide] ( #contribution-guide )
6463- [ Tutorials] ( #tutorials )
6564
6665---
@@ -505,8 +504,8 @@ export const withState = <WrappedProps extends InjectedProps>(
505504` ` ` tsx
506505import * as React from ' react' ;
507506
508- import { withState } from ' @src /hoc' ;
509- import { SFCCounter } from ' @src /components' ;
507+ import { withState } from ' .. /hoc' ;
508+ import { SFCCounter } from ' .. /components' ;
510509
511510const SFCCounterWithState =
512511 withState (SFCCounter );
@@ -589,8 +588,8 @@ export const withErrorBoundary = <WrappedProps extends InjectedProps>(
589588` ` ` tsx
590589import * as React from ' react' ;
591590
592- import { withErrorBoundary } from ' @src /hoc' ;
593- import { ErrorMessage } from ' @src /components' ;
591+ import { withErrorBoundary } from ' .. /hoc' ;
592+ import { ErrorMessage } from ' .. /components' ;
594593
595594const ErrorMessageWithErrorBoundary =
596595 withErrorBoundary (ErrorMessage );
@@ -633,14 +632,14 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({
633632#### - redux connected counter
634633
635634` ` ` tsx
635+ import Types from ' Types' ;
636636import { connect } from ' react-redux' ;
637637
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' ;
641640
642- const mapStateToProps = (state : RootState ) => ({
643- count: countersSelectors .getReduxCounter (state ),
641+ const mapStateToProps = (state : Types . RootState ) => ({
642+ count: countersSelectors .getReduxCounter (state . counters ),
644643});
645644
646645export const SFCCounterConnected = connect (mapStateToProps , {
@@ -653,7 +652,7 @@ export const SFCCounterConnected = connect(mapStateToProps, {
653652` ` ` tsx
654653import * as React from ' react' ;
655654
656- import { SFCCounterConnected } from ' @src /connected' ;
655+ import { SFCCounterConnected } from ' .. /connected' ;
657656
658657export default () => (
659658 <SFCCounterConnected
@@ -669,14 +668,14 @@ export default () => (
669668#### - redux connected counter (verbose)
670669
671670` ` ` tsx
672- import { bindActionCreators } from ' redux' ;
671+ import Types from ' Types' ;
672+ import { bindActionCreators , Dispatch } from ' redux' ;
673673import { connect } from ' react-redux' ;
674674
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' ;
678677
679- const mapStateToProps = (state : RootState ) => ({
678+ const mapStateToProps = (state : Types . RootState ) => ({
680679 count: state .counters .reduxCounter ,
681680});
682681
@@ -693,7 +692,7 @@ export const SFCCounterConnectedVerbose =
693692` ` ` tsx
694693import * as React from ' react' ;
695694
696- import { SFCCounterConnectedVerbose } from ' @src /connected' ;
695+ import { SFCCounterConnectedVerbose } from ' .. /connected' ;
697696
698697export default () => (
699698 <SFCCounterConnectedVerbose
@@ -709,18 +708,18 @@ export default () => (
709708#### - with own props
710709
711710` ` ` tsx
711+ import Types from ' Types' ;
712712import { connect } from ' react-redux' ;
713713
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' ;
717716
718717export interface SFCCounterConnectedExtendedProps {
719718 initialCount: number ;
720719}
721720
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 ,
724723});
725724
726725export const SFCCounterConnectedExtended = connect (mapStateToProps , {
@@ -733,7 +732,7 @@ export const SFCCounterConnectedExtended = connect(mapStateToProps, {
733732` ` ` tsx
734733import * as React from ' react' ;
735734
736- import { SFCCounterConnectedExtended } from ' @src /connected' ;
735+ import { SFCCounterConnectedExtended } from ' .. /connected' ;
737736
738737export default () => <SFCCounterConnectedExtended label = { ' SFCCounterConnectedExtended' } initialCount = { 10 } />;
739738
@@ -756,7 +755,7 @@ export default () => <SFCCounterConnectedExtended label={'SFCCounterConnectedExt
756755A 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.
757756
758757` ` ` tsx
759- import { action , createAction , createStandardAction } from ' typesafe-actions' ;
758+ import { action } from ' typesafe-actions' ;
760759
761760import { ADD , INCREMENT } from ' ./constants' ;
762761
@@ -770,10 +769,12 @@ export const add = (amount: number) => action(ADD, amount);
770769// https://github.com/piotrwitek/typesafe-actions#behold-the-mighty-tutorial
771770
772771// OPTION 1 (with generics):
772+ // import { createStandardAction } from 'typesafe-actions';
773773// export const increment = createStandardAction(INCREMENT)<void>();
774774// export const add = createStandardAction(ADD)<number>();
775775
776776// OPTION 2 (with resolve callback):
777+ // import { createAction } from 'typesafe-actions';
777778// export const increment = createAction(INCREMENT);
778779// export const add = createAction(ADD, resolve => {
779780// return (amount: number) => resolve(amount);
@@ -869,7 +870,7 @@ state.counterPairs[0].immutableCounter2 = 1; // TS Error: cannot be mutated
869870
870871` ` ` tsx
871872import { combineReducers } from ' redux' ;
872- import { ActionsUnion } from ' typesafe-actions' ;
873+ import { ActionType } from ' typesafe-actions' ;
873874
874875import { Todo , TodosFilter } from ' ./models' ;
875876import * as actions from ' ./actions' ;
@@ -882,7 +883,7 @@ export type TodosState = {
882883 readonly todosFilter : TodosFilter ;
883884};
884885
885- export type TodosAction = ActionsUnion < typeof actions > ;
886+ export type TodosAction = ActionType < typeof actions > ;
886887
887888export default combineReducers <TodosState , TodosAction >({
888889 isFetching : (state = false , action ) => {
@@ -1010,21 +1011,21 @@ When creating a store instance we don't need to provide any additional types. It
10101011> The resulting store instance methods like ` getState ` or ` dispatch ` will be type checked and will expose all type errors
10111012
10121013` ` ` tsx
1013- import { createStore , applyMiddleware , compose } from ' redux' ;
1014+ import { createStore , applyMiddleware } from ' redux' ;
10141015import { createEpicMiddleware } from ' redux-observable' ;
10151016
1017+ import { composeEnhancers } from ' ./utils' ;
10161018import rootReducer from ' ./root-reducer' ;
10171019import rootEpic from ' ./root-epic' ;
1020+ import services from ' ../services' ;
10181021
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+ });
10241025
10251026function configureStore(initialState ? : object ) {
10261027 // configure middlewares
1027- const middlewares = [createEpicMiddleware ( rootEpic ) ];
1028+ const middlewares = [epicMiddleware ];
10281029 // compose enhancers
10291030 const enhancer = composeEnhancers (applyMiddleware (... middlewares ));
10301031 // create store
@@ -1048,7 +1049,6 @@ export default store;
10481049### 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!
10491050
10501051` ` ` tsx
1051- // tslint:disable:no-console
10521052import Types from ' Types' ;
10531053import { combineEpics , Epic } from ' redux-observable' ;
10541054import { tap , ignoreElements , filter } from ' rxjs/operators' ;
@@ -1059,12 +1059,13 @@ import { todosConstants, TodosAction } from '../todos';
10591059// contrived example!!!
10601060const logAddAction : Epic < TodosAction , Types.RootState , Types.Services> = (
10611061 action$ ,
1062- store
1062+ store ,
1063+ { logger }
10631064) =>
10641065 action$.pipe(
10651066 filter(isOfType (todosConstants.ADD)), // action is narrowed to: { type: "ADD_TODO"; payload: string; }
10661067 tap(action = > {
1067- console .log(
1068+ logger .log(
10681069 ` action type must be equal: ${todosConstants .ADD } === ${action .type } `
10691070 );
10701071 }),
@@ -1447,33 +1448,16 @@ class StatefulCounter extends React.Component<Props, State> {
14471448
14481449---
14491450
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-
14731451# Tutorials
14741452> Curated list of relevant in-depth tutorials
14751453
14761454Higher-Order Components:
14771455- https://medium.com/@jrwebdev/react-higher-order-component-patterns-in-typescript-42278f7590fb
14781456
14791457[⇧ back to top](#table-of-contents)
1458+
1459+ ---
1460+
1461+ MIT License
1462+
1463+ Copyright (c) 2017 Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io)
0 commit comments