Skip to content

Commit

Permalink
Remove Flow, add TypeScript
Browse files Browse the repository at this point in the history
Dependencies:
- removed unused packages
- updated redux for better type definitions
- removed babel as an intermediary build step, rely on the TypeScript compiler for now
- added and configured @typescript-eslint with prettier to enforce coding styleguide
- added ts-jest for interoperability with Jest and TypeScript (configuration can be found in the package.json)
  • Loading branch information
jvhoven authored and Pouja committed Apr 4, 2019
1 parent f14c62c commit 3fb9731
Show file tree
Hide file tree
Showing 19 changed files with 5,494 additions and 322 deletions.
12 changes: 0 additions & 12 deletions .babelrc

This file was deleted.

15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
plugins: ['@typescript-eslint'],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
indent: 'off',
'@typescript-eslint/indent': ['error', 2],
},
};
8 changes: 0 additions & 8 deletions .flowconfig

This file was deleted.

8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": false,
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
36 changes: 16 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ First install the following dependencies in the package.json:
Now add the flash-message-reducer to your rootReducer for example:

```js
// @flow

import { combineReducers } from 'redux';

import type { FlashMessageStore } from 'redux-flash-messages';
import { flashMessage } from 'redux-flash-messages';
import { flashMessage, FlashMessageStore } from 'redux-flash-messages';

export type Store = {
flashMessage: FlashMessageStore
};
export interface Store {
flashMessage: FlashMessageStore;
}

// Use ES6 object literal shorthand syntax to define the object shape
const rootReducer = combineReducers({
Expand Down Expand Up @@ -68,25 +65,20 @@ The redux-flash-messages module must be configured before the application is ren
Next we need to render the flash messages from the Redux store. How you do this is entirely up to you, but here is a small example:

```js
// @flow

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Store, Dispatch } from 'redux';

import type { Store } from '../../../redux/root-reducer';
import type { Dispatch } from '../../../redux/models';

import type { FlashMessage as FlashMessageShape } from 'redux-flash-messages';
import { removeFlashMessage } from 'redux-flash-messages';
import { removeFlashMessage, FlashMessage as FlashMessageShape } from 'redux-flash-messages';

import './FlashMessage.css';

type Props = {
messages: Array<FlashMessageShape>,
dispatch: Dispatch
};
interface Props {
messages: Array<FlashMessageShape>;
dispatch: Dispatch;
}

export class FlashMessage extends Component<void, Props, void> {
export class FlashMessage extends Component<Props, {}> {

onFlashMessageClick(flashMessage: FlashMessageShape) {
/*
Expand Down Expand Up @@ -203,7 +195,11 @@ You do this by calling `addFlashMessageOfType` manually.
```js
import { addFlashMessageOfType } from 'redux-flash-messages';

enum CustomTypes {
Notice = 'NOTICE',
}

export function addNotice({ text, onClick, data }: FlashMessageConfig) {
addFlashMessageOfType('NOTICE', 1000, text, onClick, data);
addFlashMessageOfType(CustomTypes.Notice, 1000, text, onClick, data);
}
```
Loading

0 comments on commit 3fb9731

Please sign in to comment.