Skip to content

Commit

Permalink
refactor(template-react): remove flow type annotations
Browse files Browse the repository at this point in the history
This commit removes the flow type support from our default template

BREAKING CHANGE:
The template `hops-template-react` now no longer contains flow type
annotations.

Closes: #277
  • Loading branch information
ZauberNerd committed Nov 22, 2017
1 parent edd5c9a commit 50dd0f9
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 353 deletions.
15 changes: 0 additions & 15 deletions packages/template-react/.flowconfig

This file was deleted.

13 changes: 1 addition & 12 deletions packages/template-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
[![npm](https://img.shields.io/npm/v/hops-template-react.svg)](https://www.npmjs.com/package/hops-template-react)

This is a small example application showing [hops](https://github.com/xing/hops) in action.
It demonstrates how to use hops with React, Redux, Flow and Jest.
It demonstrates how to use hops with React, Redux and Jest.

It has the following folder structure:

```
├── flow-typed
├── node_modules
├── package.json
├── readme.md
Expand Down Expand Up @@ -75,16 +74,6 @@ To make use of this execute `npm run build -- --static` or `yarn build --static`
This command will test your code with [jest](https://facebook.github.io/jest/) a testrunner by facebook that integrates nicely with react.


### `npm run flow` / `yarn flow`

This command will run flow to typecheck your code and warn you about errors early on.


### (`postinstall`)

This script isn't really meant to be executed by the user. Instead it will run every time that you install the project or a new dependency and download the latest type definitions from [flow-typed](https://github.com/flowtype/flow-typed) for all of your dependencies.


## Configuration

Please refer to [hops-config](https://github.com/xing/hops/tree/master/packages/config) to see a list of all supported options.
Expand Down
3 changes: 0 additions & 3 deletions packages/template-react/flow-typed/css-module.js

This file was deleted.

6 changes: 1 addition & 5 deletions packages/template-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
}
},
"scripts": {
"postinstall": "flow-typed install --overwrite",
"start": "hops start",
"build": "hops build",
"test": "jest",
"flow": "flow"
"test": "jest"
},
"dependencies": {
"hops-express": "7.3.4",
Expand All @@ -33,8 +31,6 @@
"redux-thunk": "^2.2.0"
},
"devDependencies": {
"flow-bin": "^0.58.0",
"flow-typed": "^2.2.3",
"hops-build": "7.4.1",
"hops-local-cli": "7.4.0",
"jest": "^21.2.1",
Expand Down
1 change: 0 additions & 1 deletion packages/template-react/src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import React from 'react';
import { Route, Switch, Link } from 'react-router-dom';

Expand Down
20 changes: 2 additions & 18 deletions packages/template-react/src/counter/actions.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
// @flow

import { INCREMENT, DECREMENT } from './constants';

type IncrementAction = {
type: typeof INCREMENT;
payload: number;
};

type DecrementAction = {
type: typeof DECREMENT;
payload: number;
};

export type Action =
| IncrementAction
| DecrementAction;

export function increment(amount: number = 1): IncrementAction {
export function increment(amount = 1) {
return {
type: INCREMENT,
payload: amount,
};
}

export function decrement(amount: number = 1): DecrementAction {
export function decrement(amount = 1) {
return {
type: DECREMENT,
payload: amount,
Expand Down
6 changes: 2 additions & 4 deletions packages/template-react/src/counter/constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
// @flow

export const INCREMENT: 'INCREMENT_COUNTER' = 'INCREMENT_COUNTER';
export const DECREMENT: 'DECREMENT_COUNTER' = 'DECREMENT_COUNTER';
export const INCREMENT = 'INCREMENT_COUNTER';
export const DECREMENT = 'DECREMENT_COUNTER';
21 changes: 8 additions & 13 deletions packages/template-react/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// @flow

import React from 'react';
import PropTypes from 'prop-types';

export type Props = {
count: number;
increment: (amount?: number) => void;
decrement: (amount?: number) => void;
};

export default function Counter({
count,
increment,
decrement,
}: Props) {
export default function Counter({ count, increment, decrement }) {
return (
<div>
<span>Clicked: {count} times</span>
Expand All @@ -21,3 +10,9 @@ export default function Counter({
</div>
);
}

Counter.propTypes = {
count: PropTypes.number.isRequired,
increment: PropTypes.func.isRequired,
decrement: PropTypes.func.isRequired,
};
7 changes: 2 additions & 5 deletions packages/template-react/src/counter/counterContainer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// @flow

import { connect } from 'react-redux';

import { increment, decrement } from './actions';
import type { ApplicationState } from '../reducers';

import Counter from './counter';

export const mapStateToProps = ({ counter }: ApplicationState) => ({
export const mapStateToProps = ({ counter }) => ({
count: counter,
});

Expand All @@ -16,4 +13,4 @@ export const actionCreators = {
decrement,
};

export default connect(mapStateToProps, actionCreators)(Counter);
export default connect(mapStateToProps, actionCreators)(Counter);
4 changes: 1 addition & 3 deletions packages/template-react/src/counter/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
// @flow

export { default as Counter } from './counterContainer';
export { default as Counter } from './counterContainer';
8 changes: 1 addition & 7 deletions packages/template-react/src/counter/reducer.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// @flow

import { INCREMENT, DECREMENT } from './constants';
import type { Action } from './actions';

export type State = number;

export default function counter(state: State = 0, action: Action): State {
export default function counter(state = 0, action) {
switch (action.type) {
case INCREMENT:
return state + action.payload;
case DECREMENT:
return state - action.payload;
default:
(action: empty);
return state;
}
}
2 changes: 0 additions & 2 deletions packages/template-react/src/counter/spec/actions.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @flow

import { INCREMENT, DECREMENT } from '../constants';
import { increment, decrement } from '../actions';

Expand Down
2 changes: 0 additions & 2 deletions packages/template-react/src/counter/spec/counter.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @flow

import React from 'react';
import renderer from 'react-test-renderer';
import Counter from '../counter';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @flow

import React from 'react';
import renderer from 'react-test-renderer';
import CounterContainer, { mapStateToProps } from '../counterContainer';
Expand All @@ -25,4 +23,4 @@ describe('Counter container', () => {
it('selects correct state slice', () => {
expect(mapStateToProps({ counter: 3 })).toEqual({ count: 3 });
});
});
});
6 changes: 1 addition & 5 deletions packages/template-react/src/counter/spec/reducer.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// @flow

import counter from '../reducer';
import { increment, decrement } from '../actions';

describe('Counter reducer', () => {
it('initializes with 0', () => {
// $FlowExpectError - action must be a union of increment|decrement
expect(counter(undefined, {})).toBe(0);
});

Expand All @@ -22,7 +19,6 @@ describe('Counter reducer', () => {
});

it('returns current state on unknown action', () => {
// $FlowExpectError - action must be a union of increment|decrement
expect(counter(5, { type: 'FOO' })).toBe(5);
});
});
});
1 change: 0 additions & 1 deletion packages/template-react/src/home/home.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import React from 'react';
import Helmet from 'react-helmet';

Expand Down
4 changes: 1 addition & 3 deletions packages/template-react/src/home/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
// @flow

export { default as Home } from './home';
export { default as Home } from './home';
2 changes: 0 additions & 2 deletions packages/template-react/src/home/spec/home.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @flow

import React from 'react';
import renderer from 'react-test-renderer';
import { Home } from '../';
Expand Down
8 changes: 1 addition & 7 deletions packages/template-react/src/reducers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// @flow

import counter, { type State as CounterState } from './counter/reducer';
import counter from './counter/reducer';

const reducer = {
counter
};

export type ApplicationState = {
counter: CounterState;
};

export default reducer;
Loading

0 comments on commit 50dd0f9

Please sign in to comment.