Skip to content

Commit 7cb59ab

Browse files
committed
migrated to TS 2.1 with noImplicitAny + strictNullChecks
1 parent 3bfd50f commit 7cb59ab

File tree

17 files changed

+141
-117
lines changed

17 files changed

+141
-117
lines changed

src/app.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { HomeContainer } from './containers/home-container/index';
1010
import { CssModulesContainer } from './containers/css-modules-container/index';
1111
import CurrencyConverterContainer from './containers/currency-converter-container/index';
1212

13-
import { store } from './store';
13+
import { store } from './store/index';
1414
const history = syncHistoryWithStore(hashHistory, store) as any;
1515

1616
function App() {
1717
return (
1818
<Provider store={store}>
1919
<Router history={history}>
2020
<Route component={MainLayout}>
21-
<Route path="/" component={HomeContainer}/>
22-
<Route path="/currency-converter" component={CurrencyConverterContainer}/>
23-
<Route path="/css-modules" component={CssModulesContainer}/>
21+
<Route path="/" component={HomeContainer} />
22+
<Route path="/currency-converter" component={CurrencyConverterContainer} />
23+
<Route path="/css-modules" component={CssModulesContainer} />
2424
</Route>
2525
</Router>
2626
</Provider>

src/containers/currency-converter-container/components/currency-converter.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
// lib imports
22
import * as React from 'react';
3+
import { Action } from 'redux-actions';
34

45
import { CurrencySelect } from './currency-select';
56
import { CurrencyInput } from './currency-input';
67

7-
interface LocalProps {
8+
interface IProps {
89
currencies: string[];
910
baseCurrency: string;
1011
targetCurrency: string;
11-
baseValue: number;
12-
targetValue: number;
13-
onBaseCurrencyChange: (newCurrency: string) => FluxStandardAction<string>;
14-
onTargetCurrencyChange: (newCurrency: string) => FluxStandardAction<string>;
15-
onBaseValueChange: (newCurrency: string) => FluxStandardAction<string>;
16-
onTargetValueChange: (newCurrency: string) => FluxStandardAction<string>;
12+
baseValue: string;
13+
targetValue: string;
14+
onBaseCurrencyChange: (payload: string) => Action<string>;
15+
onTargetCurrencyChange: (payload: string) => Action<string>;
16+
onBaseValueChange: (payload: string) => Action<string>;
17+
onTargetValueChange: (payload: string) => Action<string>;
1718
}
1819

19-
interface LocalState {
20+
interface IState {
2021
}
2122

22-
export class CurrencyConverter extends React.Component<LocalProps, LocalState> {
23+
export class CurrencyConverter extends React.Component<IProps, IState> {
2324
render(): JSX.Element {
2425
const {
2526
currencies,
@@ -56,8 +57,15 @@ export class CurrencyConverter extends React.Component<LocalProps, LocalState> {
5657
}
5758
}
5859

60+
interface ICurrencyInputGroup {
61+
currencies: string[];
62+
currencyType: string;
63+
currencyValue: string;
64+
onCurrencyTypeChange: (payload: string) => Action<string>;
65+
onCurrencyValueChange: (payload: string) => Action<string>;
66+
}
5967
function CurrencyInputGroup({currencies, currencyType, currencyValue,
60-
onCurrencyTypeChange, onCurrencyValueChange}) {
68+
onCurrencyTypeChange, onCurrencyValueChange}: ICurrencyInputGroup) {
6169
return (
6270
<div className="c-input-group">
6371
<div className="o-field o-field--fixed" style={{ width: '80px' }}>

src/containers/currency-converter-container/components/currency-input.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import * as React from 'react';
2+
import { Action } from 'redux-actions';
3+
24
interface IProps {
3-
value: number;
4-
onChange: (newValue: string) => FluxStandardAction<string>;
5+
value: string;
6+
onChange: (newValue: string) => Action<string>;
57
}
68

7-
export function CurrencyInput({value = 0, onChange = null}: IProps) {
9+
export function CurrencyInput({value = 0, onChange}: IProps) {
810

9-
const handleChange = (ev) => {
11+
const handleChange = (ev: React.SyntheticEvent<HTMLInputElement>) => {
1012
onChange(ev.target.value);
1113
};
1214

src/containers/currency-converter-container/components/currency-select.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import * as React from 'react';
2+
import { Action } from 'redux-actions';
3+
24
interface IProps {
35
currencies: string[];
46
value: string;
5-
onChange: (newValue: string) => FluxStandardAction<string>;
7+
onChange: (newValue: string) => Action<string>;
68
}
79

8-
export function CurrencySelect({currencies = [], value = null, onChange = null}: IProps) {
10+
export function CurrencySelect({currencies = [], value, onChange}: IProps) {
911

10-
const handleChange = (ev) => {
12+
const handleChange = (ev: React.SyntheticEvent<HTMLSelectElement>) => {
1113
onChange(ev.target.value);
1214
};
1315

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
// lib imports
22
import * as React from 'react';
3-
import { bindActionCreators } from 'redux';
3+
import { Action } from 'redux-actions';
44
import { connect } from 'react-redux';
55
// components imports
6+
import { IRootReducer } from '../../store';
7+
import { ICurrencyRates } from '../../store/currency-rates-reducer';
8+
import { ICurrencyConverter } from '../../store/currency-converter-reducer';
69
import { PageHeader } from '../../components/page-header';
710
import { PageSection } from '../../components/page-section';
8-
import * as currencyConverterActions from '../../reducers/currency-converter-reducer';
11+
import * as currencyConverterActions from '../../store/currency-converter-reducer';
912
import { CurrencyConverter } from './components/currency-converter';
1013

1114
interface IProps {
12-
currencyConverter: any;
13-
currencyRates: any;
14-
actions: any;
15+
currencyRates: ICurrencyRates;
16+
currencyConverter: ICurrencyConverter;
17+
updateBaseCurrency: (payload: string) => Action<string>;
18+
updateBaseValue: (payload: string) => Action<string>;
19+
updateTargetCurrency: (payload: string) => Action<string>;
20+
updateTargetValue: (payload: string) => Action<string>;
1521
}
16-
1722
interface IState {
1823
}
1924

2025
export class CurrencyConverterContainer extends React.Component<IProps, IState> {
2126
render() {
2227
const { baseCurrency, targetCurrency, baseValue, targetValue } = this.props.currencyConverter;
2328
const { currencies } = this.props.currencyRates;
24-
const { actions } = this.props;
29+
const { updateBaseCurrency, updateBaseValue, updateTargetCurrency, updateTargetValue } = this.props;
2530

2631
return (
2732
<article>
@@ -31,29 +36,22 @@ export class CurrencyConverterContainer extends React.Component<IProps, IState>
3136
<CurrencyConverter currencies={currencies}
3237
baseCurrency={baseCurrency} targetCurrency={targetCurrency}
3338
baseValue={baseValue} targetValue={targetValue}
34-
onBaseCurrencyChange={actions.updateBaseCurrency}
35-
onTargetCurrencyChange={actions.updateTargetCurrency}
36-
onBaseValueChange={actions.updateBaseValue}
37-
onTargetValueChange={actions.updateTargetValue}
39+
onBaseCurrencyChange={updateBaseCurrency}
40+
onTargetCurrencyChange={updateTargetCurrency}
41+
onBaseValueChange={updateBaseValue}
42+
onTargetValueChange={updateTargetValue}
3843
/>
3944
</section>
4045
</article>
4146
);
4247
}
4348
}
4449

45-
function mapStateToProps(state) {
46-
return {
47-
currencyConverter: state.currencyConverter,
48-
currencyRates: state.currencyRates
49-
};
50-
}
50+
const stateToProps = (storeState: IRootReducer) => ({
51+
currencyRates: storeState.currencyRates,
52+
currencyConverter: storeState.currencyConverter
53+
});
5154

52-
const actions = Object.assign({}, currencyConverterActions);
53-
function mapDispatchToProps(dispatch) {
54-
return {
55-
actions: bindActionCreators(actions, dispatch)
56-
};
57-
}
55+
const actionsToProps = Object.assign({}, currencyConverterActions);
5856

59-
export default connect(mapStateToProps, mapDispatchToProps)(CurrencyConverterContainer);
57+
export default connect(stateToProps, actionsToProps)(CurrencyConverterContainer);

src/reducers/index.tsx

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/services/fixer/currency-rates.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const FIXER_API_URL = 'https://api.fixer.io/';
66

77
// http://api.fixer.io/latest
88
export async function getLatest(baseCurrency?: string):
9-
Promise<IFixerServiceResponse> {
9+
Promise<IFixerServiceResponse | null> {
1010
let fixerLatestRates = FIXER_API_URL + 'latest';
1111
if (baseCurrency) {
1212
fixerLatestRates += '?base=' + baseCurrency;
@@ -18,13 +18,13 @@ export async function getLatest(baseCurrency?: string):
1818
return response.json();
1919
} catch (err) {
2020
logRejection(err);
21-
return undefined;
21+
return null;
2222
}
2323
}
2424

2525
// http://api.fixer.io/2000-01-03
2626
export async function getByDate(date: Date, baseCurrency?: string):
27-
Promise<IFixerServiceResponse> {
27+
Promise<IFixerServiceResponse | null> {
2828
let fixerRatesByDate = FIXER_API_URL + date.toISOString().slice(0, 10);
2929
if (baseCurrency) {
3030
fixerRatesByDate += '?base=' + baseCurrency;
@@ -36,6 +36,6 @@ export async function getByDate(date: Date, baseCurrency?: string):
3636
return response.json();
3737
} catch (err) {
3838
logRejection(err);
39-
return undefined;
39+
return null;
4040
}
4141
}

src/services/local-storage/app-store.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const INITIAL_DATE = (new Date()).toISOString();
44

55
export class AppStore {
66
// initial state
7+
[key: string]: any;
78
currencies = '{}';
89
fromCurrency = 'SEK';
910
toCurrency = 'EUR';
@@ -16,9 +17,9 @@ export class AppStore {
1617
this.load();
1718
}
1819

19-
save(stateObject) {
20+
save(stateObject: any) {
2021
// remember to stringify the objects that you want to store
21-
Object.keys(stateObject).forEach(key => {
22+
Object.keys(stateObject).forEach((key) => {
2223
const storageKey = STORAGE_PREFIX + key;
2324
const stateItem = stateObject[key];
2425
if (stateItem) {

src/store.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/reducers/currency-converter-reducer.tsx renamed to src/store/currency-converter-reducer.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createAction } from 'redux-actions';
2-
import Immutable from 'seamless-immutable';
1+
import { createAction, Action } from 'redux-actions';
2+
import * as Immutable from 'seamless-immutable';
33

44
// Action Types - LOAD, CREATE, UPDATE, REMOVE
55
const UPDATE_BASE_CURRENCY = 'currencyConverter/UPDATE_BASE_CURRENCY';
@@ -10,18 +10,24 @@ const UPDATE_TARGET_VALUE = 'currencyConverter/UPDATE_TARGET_VALUE';
1010
// Action Creators
1111
export const updateBaseCurrency = createAction<string>(UPDATE_BASE_CURRENCY);
1212
export const updateTargetCurrency = createAction<string>(UPDATE_TARGET_CURRENCY);
13-
export const updateBaseValue = createAction<number>(UPDATE_BASE_VALUE);
14-
export const updateTargetValue = createAction<number>(UPDATE_TARGET_VALUE);
13+
export const updateBaseValue = createAction<string>(UPDATE_BASE_VALUE);
14+
export const updateTargetValue = createAction<string>(UPDATE_TARGET_VALUE);
1515

1616
// Reducer
17-
const initialState = Immutable({
17+
export interface ICurrencyConverter {
18+
baseCurrency: string;
19+
targetCurrency: string;
20+
baseValue: string;
21+
targetValue: string;
22+
}
23+
const initialState: ICurrencyConverter = {
1824
baseCurrency: 'PLN',
1925
targetCurrency: 'SEK',
20-
baseValue: 0,
21-
targetValue: 0
22-
});
26+
baseValue: '0',
27+
targetValue: '0'
28+
};
2329

24-
export default function reducer(state = initialState, action: FluxStandardAction<any>) {
30+
export default function reducer(state = Immutable.from(initialState), action: Action<any>) {
2531
switch (action.type) {
2632
case UPDATE_BASE_CURRENCY:
2733
return state.merge({

0 commit comments

Comments
 (0)