Skip to content

Commit ea71eb8

Browse files
committed
code refactoring and cleaning
1 parent 2678e29 commit ea71eb8

22 files changed

+67
-357
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const incrementCount = () => count++;
102102

103103
export default () => (
104104
<SFCCounter
105-
label='SFCCounter'
105+
label={'SFCCounter'}
106106
count={count}
107107
onIncrement={incrementCount}
108108
/>
@@ -148,7 +148,6 @@ export default () => (
148148
/>
149149
);
150150

151-
152151
```
153152
</p></details>
154153

@@ -270,7 +269,7 @@ export const StatefulCounterWithInitialCount: React.ComponentClass<StatefulCount
270269
</div>
271270
);
272271
}
273-
}
272+
};
274273

275274
```
276275

@@ -305,7 +304,7 @@ import * as React from 'react';
305304
export interface GenericListProps<T> {
306305
items: T[],
307306
itemRenderer: (item: T) => JSX.Element,
308-
};
307+
}
309308

310309
export class GenericList<T> extends React.Component<GenericListProps<T>, {}> {
311310
render() {
@@ -326,7 +325,7 @@ export class GenericList<T> extends React.Component<GenericListProps<T>, {}> {
326325
```tsx
327326
import * as React from 'react';
328327

329-
import { IUser } from '@src/models'
328+
import { IUser } from '@src/models';
330329
import { GenericList } from '@src/components';
331330

332331
export const UserList = class extends GenericList<IUser> { };
@@ -373,7 +372,7 @@ import { SFCCounterConnected } from '@src/connected';
373372

374373
export default () => (
375374
<SFCCounterConnected
376-
label="SFCCounterConnected"
375+
label={'SFCCounterConnected'}
377376
/>
378377
);
379378

@@ -414,7 +413,7 @@ import { SFCCounterConnectedVerbose } from '@src/connected';
414413

415414
export default () => (
416415
<SFCCounterConnectedVerbose
417-
label="SFCCounterConnectedVerbose"
416+
label={'SFCCounterConnectedVerbose'}
418417
/>
419418
);
420419

@@ -455,7 +454,7 @@ import { SFCCounterConnectedExtended } from '@src/connected';
455454

456455
export default () => (
457456
<SFCCounterConnectedExtended
458-
label="SFCCounterConnectedExtended"
457+
label={'SFCCounterConnectedExtended'}
459458
initialCount={10}
460459
/>
461460
);
@@ -495,7 +494,7 @@ export function withState<WrappedComponentProps extends RequiredProps>(
495494

496495
state: State = {
497496
count: 0,
498-
}
497+
};
499498

500499
handleIncrement = () => {
501500
this.setState({ count: this.state.count + 1 });
@@ -650,7 +649,7 @@ export type Actions = {
650649
};
651650

652651
// Action Creators
653-
export const actionCreatorss = {
652+
export const actionCreators = {
654653
incrementSfc: (): Actions[typeof INCREMENT_SFC] => ({
655654
type: INCREMENT_SFC,
656655
}),
@@ -666,7 +665,7 @@ export const actionCreatorss = {
666665
import store from '@src/store';
667666
import { actionCreators } from '@src/redux/counters';
668667

669-
store.dispatch(actionCreators.incrementSfc(1)); // Error: Expected 0 arguments, but got 1.
668+
// store.dispatch(actionCreators.incrementSfc(1)); // Error: Expected 0 arguments, but got 1.
670669
store.dispatch(actionCreators.incrementSfc()); // OK => { type: "INCREMENT_SFC" }
671670

672671
```
@@ -710,7 +709,7 @@ Relevant TypeScript Docs references:
710709
- [Discriminated Union types](https://www.typescriptlang.org/docs/handbook/advanced-types.html)
711710
- [Mapped types](https://www.typescriptlang.org/docs/handbook/advanced-types.html) e.g. `Readonly` & `Partial`
712711

713-
### Typing Reducer State
712+
### Reducer State
714713
Declare reducer `State` type definition with readonly modifier for `type level` immutability
715714
```ts
716715
export type State = {
@@ -796,16 +795,18 @@ export const reducer = combineReducers<State, RootAction>({
796795

797796
### Reducer with static `type` property from helper factory function - `createActionCreator`
798797
```ts
799-
export default function reducer(state = 0, action: RootAction): State {
800-
switch (action.type) {
801-
case actionCreators.increment.type:
802-
return state.counter + 1;
803-
case actionCreators.decrement.type:
804-
return state.counter - 1;
805-
806-
default: return state;
807-
}
808-
}
798+
export const reducer: Reducer<State> =
799+
(state = 0, action: RootAction) => {
800+
switch (action.type) {
801+
case actionCreators.increment.type:
802+
return state + 1;
803+
804+
case actionCreators.decrement.type:
805+
return state - 1;
806+
807+
default: return state;
808+
}
809+
};
809810
```
810811

811812
---
@@ -869,8 +870,7 @@ export const rootReducer = combineReducers<RootState, RootAction>({
869870
```tsx
870871
import { createStore, applyMiddleware, compose } from 'redux';
871872
import { createEpicMiddleware } from 'redux-observable';
872-
import { rootReducer, rootEpic } from '@src/redux';
873-
import { RootState } from '@src/redux';
873+
import { rootReducer, rootEpic, RootState } from '@src/redux';
874874

875875
const composeEnhancers = (
876876
process.env.NODE_ENV === 'development' &&

generator/content/2_redux.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Relevant TypeScript Docs references:
5151
- [Discriminated Union types](https://www.typescriptlang.org/docs/handbook/advanced-types.html)
5252
- [Mapped types](https://www.typescriptlang.org/docs/handbook/advanced-types.html) e.g. `Readonly` & `Partial`
5353

54-
### Typing Reducer State
54+
### Reducer State
5555
Declare reducer `State` type definition with readonly modifier for `type level` immutability
5656
```ts
5757
export type State = {
@@ -108,16 +108,18 @@ state.countersCollection[0].readonlyCounter2 = 1; // Error, cannot be mutated
108108

109109
### Reducer with static `type` property from helper factory function - `createActionCreator`
110110
```ts
111-
export default function reducer(state = 0, action: RootAction): State {
112-
switch (action.type) {
113-
case actionCreators.increment.type:
114-
return state.counter + 1;
115-
case actionCreators.decrement.type:
116-
return state.counter - 1;
117-
118-
default: return state;
119-
}
120-
}
111+
export const reducer: Reducer<State> =
112+
(state = 0, action: RootAction) => {
113+
switch (action.type) {
114+
case actionCreators.increment.type:
115+
return state + 1;
116+
117+
case actionCreators.decrement.type:
118+
return state - 1;
119+
120+
default: return state;
121+
}
122+
};
121123
```
122124

123125
---

playground/src/components/error-message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const ErrorMessage: React.SFC<{ onReset: () => any }> = ({ onReset }) =>
44
const handleReset = () => {
55
onReset();
66
// TODO: switch location with router
7-
}
7+
};
88

99
return (
1010
<div>

playground/src/components/generic-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
export interface GenericListProps<T> {
44
items: T[],
55
itemRenderer: (item: T) => JSX.Element,
6-
};
6+
}
77

88
export class GenericList<T> extends React.Component<GenericListProps<T>, {}> {
99
render() {

playground/src/components/generic-list.usage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22

3-
import { IUser } from '@src/models'
3+
import { IUser } from '@src/models';
44
import { GenericList } from '@src/components';
55

66
export const UserList = class extends GenericList<IUser> { };

playground/src/components/sfc-counter.usage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const incrementCount = () => count++;
77

88
export default () => (
99
<SFCCounter
10-
label='SFCCounter'
10+
label={'SFCCounter'}
1111
count={count}
1212
onIncrement={incrementCount}
1313
/>

playground/src/components/sfc-spread-attributes.usage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ export default () => (
77
style={{ backgroundColor: 'lightcyan' }}
88
/>
99
);
10-

playground/src/components/stateful-counter-with-initial-count.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ export const StatefulCounterWithInitialCount: React.ComponentClass<StatefulCount
5151
</div>
5252
);
5353
}
54-
}
54+
};

playground/src/connected/sfc-counter-connected-extended.usage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SFCCounterConnectedExtended } from '@src/connected';
44

55
export default () => (
66
<SFCCounterConnectedExtended
7-
label="SFCCounterConnectedExtended"
7+
label={'SFCCounterConnectedExtended'}
88
initialCount={10}
99
/>
1010
);

playground/src/connected/sfc-counter-connected-verbose.usage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { SFCCounterConnectedVerbose } from '@src/connected';
44

55
export default () => (
66
<SFCCounterConnectedVerbose
7-
label="SFCCounterConnectedVerbose"
7+
label={'SFCCounterConnectedVerbose'}
88
/>
99
);

0 commit comments

Comments
 (0)