From ec75d3a4b62d0f4b8d52a739a7727142421cc261 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Thu, 10 Sep 2020 11:45:02 -0400 Subject: [PATCH] feat(redux-devtools-slider-monitor): convert example to TypeScript (#632) --- package.json | 1 + .../examples/todomvc/.babelrc | 6 +- .../examples/todomvc/.eslintrc.js | 21 +++++ .../examples/todomvc/actions/TodoActions.js | 42 ---------- .../examples/todomvc/actions/TodoActions.ts | 82 +++++++++++++++++++ .../components/{Footer.js => Footer.tsx} | 23 ++++-- .../components/{Header.js => Header.tsx} | 8 +- .../{MainSection.js => MainSection.tsx} | 46 +++++++---- .../components/{TodoItem.js => TodoItem.tsx} | 28 +++++-- .../{TodoTextInput.js => TodoTextInput.tsx} | 38 ++++++--- .../{ActionTypes.js => ActionTypes.ts} | 0 .../{TodoFilters.js => TodoFilters.ts} | 5 ++ .../containers/{DevTools.js => DevTools.tsx} | 2 +- .../containers/{Root.dev.js => Root.dev.tsx} | 11 ++- .../examples/todomvc/containers/Root.js | 6 -- .../examples/todomvc/containers/Root.prod.js | 19 ----- .../examples/todomvc/containers/Root.prod.tsx | 26 ++++++ .../examples/todomvc/containers/Root.ts | 15 ++++ .../examples/todomvc/containers/TodoApp.js | 33 -------- .../examples/todomvc/containers/TodoApp.tsx | 45 ++++++++++ .../examples/todomvc/index.js | 23 ------ .../examples/todomvc/index.tsx | 29 +++++++ .../examples/todomvc/package.json | 26 ++++-- .../todomvc/reducers/{index.js => index.ts} | 6 +- .../todomvc/reducers/{todos.js => todos.ts} | 13 ++- .../todomvc/store/configureStore.dev.js | 19 ----- .../todomvc/store/configureStore.dev.ts | 26 ++++++ .../examples/todomvc/store/configureStore.js | 6 -- .../todomvc/store/configureStore.prod.js | 6 -- .../todomvc/store/configureStore.prod.ts | 8 ++ .../examples/todomvc/store/configureStore.ts | 13 +++ .../examples/todomvc/tsconfig.json | 4 + .../examples/todomvc/tsconfig.webpack.json | 4 + .../examples/todomvc/webpack.config.prod.js | 8 -- .../{webpack.config.js => webpack.config.ts} | 30 ++++--- .../examples/todomvc/containers/Root.ts | 2 +- .../examples/todomvc/package.json | 3 +- 37 files changed, 444 insertions(+), 239 deletions(-) create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/.eslintrc.js delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.js create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.ts rename packages/redux-devtools-slider-monitor/examples/todomvc/components/{Footer.js => Footer.tsx} (74%) rename packages/redux-devtools-slider-monitor/examples/todomvc/components/{Header.js => Header.tsx} (77%) rename packages/redux-devtools-slider-monitor/examples/todomvc/components/{MainSection.js => MainSection.tsx} (67%) rename packages/redux-devtools-slider-monitor/examples/todomvc/components/{TodoItem.js => TodoItem.tsx} (76%) rename packages/redux-devtools-slider-monitor/examples/todomvc/components/{TodoTextInput.js => TodoTextInput.tsx} (62%) rename packages/redux-devtools-slider-monitor/examples/todomvc/constants/{ActionTypes.js => ActionTypes.ts} (100%) rename packages/redux-devtools-slider-monitor/examples/todomvc/constants/{TodoFilters.js => TodoFilters.ts} (56%) rename packages/redux-devtools-slider-monitor/examples/todomvc/containers/{DevTools.js => DevTools.tsx} (81%) rename packages/redux-devtools-slider-monitor/examples/todomvc/containers/{Root.dev.js => Root.dev.tsx} (56%) delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/containers/Root.js delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/containers/Root.prod.js create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/containers/Root.prod.tsx create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/containers/Root.ts delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/containers/TodoApp.js create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/containers/TodoApp.tsx delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/index.js create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/index.tsx rename packages/redux-devtools-slider-monitor/examples/todomvc/reducers/{index.js => index.ts} (58%) rename packages/redux-devtools-slider-monitor/examples/todomvc/reducers/{todos.js => todos.ts} (77%) delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/store/configureStore.dev.js create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/store/configureStore.dev.ts delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/store/configureStore.js delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/store/configureStore.prod.js create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/store/configureStore.prod.ts create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/store/configureStore.ts create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/tsconfig.json create mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/tsconfig.webpack.json delete mode 100644 packages/redux-devtools-slider-monitor/examples/todomvc/webpack.config.prod.js rename packages/redux-devtools-slider-monitor/examples/todomvc/{webpack.config.js => webpack.config.ts} (75%) diff --git a/package.json b/package.json index c21a3c04..730f78de 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "@types/node": "^14.6.0", "@types/webpack": "^4.41.21", "@types/webpack-dev-server": "^3.11.0", + "@types/webpack-env": "^1.15.2", "@typescript-eslint/eslint-plugin": "^3.9.0", "@typescript-eslint/parser": "^3.9.0", "babel-eslint": "^10.1.0", diff --git a/packages/redux-devtools-slider-monitor/examples/todomvc/.babelrc b/packages/redux-devtools-slider-monitor/examples/todomvc/.babelrc index 3d0797a7..a01c7adc 100644 --- a/packages/redux-devtools-slider-monitor/examples/todomvc/.babelrc +++ b/packages/redux-devtools-slider-monitor/examples/todomvc/.babelrc @@ -1,5 +1,9 @@ { - "presets": ["@babel/preset-env", "@babel/preset-react"], + "presets": [ + "@babel/preset-env", + "@babel/preset-react", + "@babel/preset-typescript" + ], "plugins": [ "@babel/plugin-proposal-class-properties", "react-hot-loader/babel" diff --git a/packages/redux-devtools-slider-monitor/examples/todomvc/.eslintrc.js b/packages/redux-devtools-slider-monitor/examples/todomvc/.eslintrc.js new file mode 100644 index 00000000..70e1445e --- /dev/null +++ b/packages/redux-devtools-slider-monitor/examples/todomvc/.eslintrc.js @@ -0,0 +1,21 @@ +module.exports = { + extends: '../../../../.eslintrc', + overrides: [ + { + files: ['*.ts', '*.tsx'], + extends: '../../../../eslintrc.ts.react.base.json', + parserOptions: { + tsconfigRootDir: __dirname, + project: ['./tsconfig.json'], + }, + }, + { + files: ['webpack.config.ts'], + extends: '../../../../eslintrc.ts.base.json', + parserOptions: { + tsconfigRootDir: __dirname, + project: ['./tsconfig.webpack.json'], + }, + }, + ], +}; diff --git a/packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.js b/packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.js deleted file mode 100644 index f0122846..00000000 --- a/packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.js +++ /dev/null @@ -1,42 +0,0 @@ -import * as types from '../constants/ActionTypes'; - -export function addTodo(text) { - return { - type: types.ADD_TODO, - text, - }; -} - -export function deleteTodo(id) { - return { - type: types.DELETE_TODO, - id, - }; -} - -export function editTodo(id, text) { - return { - type: types.EDIT_TODO, - id, - text, - }; -} - -export function markTodo(id) { - return { - type: types.MARK_TODO, - id, - }; -} - -export function markAll() { - return { - type: types.MARK_ALL, - }; -} - -export function clearMarked() { - return { - type: types.CLEAR_MARKED, - }; -} diff --git a/packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.ts b/packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.ts new file mode 100644 index 00000000..4169e9c1 --- /dev/null +++ b/packages/redux-devtools-slider-monitor/examples/todomvc/actions/TodoActions.ts @@ -0,0 +1,82 @@ +import * as types from '../constants/ActionTypes'; + +interface AddTodoAction { + type: typeof types.ADD_TODO; + text: string; +} +export function addTodo(text: string): AddTodoAction { + return { + type: types.ADD_TODO, + text, + }; +} + +interface DeleteTodoAction { + type: typeof types.DELETE_TODO; + id: number; +} +export function deleteTodo(id: number): DeleteTodoAction { + return { + type: types.DELETE_TODO, + id, + }; +} + +interface EditTodoAction { + type: typeof types.EDIT_TODO; + id: number; + text: string; +} +export function editTodo(id: number, text: string): EditTodoAction { + return { + type: types.EDIT_TODO, + id, + text, + }; +} + +interface MarkTodoAction { + type: typeof types.MARK_TODO; + id: number; +} +export function markTodo(id: number): MarkTodoAction { + return { + type: types.MARK_TODO, + id, + }; +} + +interface MarkAllAction { + type: typeof types.MARK_ALL; +} +export function markAll(): MarkAllAction { + return { + type: types.MARK_ALL, + }; +} + +interface ClearMarkedAction { + type: typeof types.CLEAR_MARKED; +} +export function clearMarked(): ClearMarkedAction { + return { + type: types.CLEAR_MARKED, + }; +} + +export type TodoAction = + | AddTodoAction + | DeleteTodoAction + | EditTodoAction + | MarkTodoAction + | MarkAllAction + | ClearMarkedAction; + +export interface TodoActions { + addTodo(text: string): AddTodoAction; + deleteTodo(id: number): DeleteTodoAction; + editTodo(id: number, text: string): EditTodoAction; + markTodo(id: number): MarkTodoAction; + markAll(): MarkAllAction; + clearMarked(): ClearMarkedAction; +} diff --git a/packages/redux-devtools-slider-monitor/examples/todomvc/components/Footer.js b/packages/redux-devtools-slider-monitor/examples/todomvc/components/Footer.tsx similarity index 74% rename from packages/redux-devtools-slider-monitor/examples/todomvc/components/Footer.js rename to packages/redux-devtools-slider-monitor/examples/todomvc/components/Footer.tsx index f583f39e..9462dd0c 100644 --- a/packages/redux-devtools-slider-monitor/examples/todomvc/components/Footer.js +++ b/packages/redux-devtools-slider-monitor/examples/todomvc/components/Footer.tsx @@ -1,7 +1,12 @@ -import React, { Component } from 'react'; +import React, { Component, MouseEventHandler } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; -import { SHOW_ALL, SHOW_MARKED, SHOW_UNMARKED } from '../constants/TodoFilters'; +import { + SHOW_ALL, + SHOW_MARKED, + SHOW_UNMARKED, + TodoFilter, +} from '../constants/TodoFilters'; const FILTER_TITLES = { [SHOW_ALL]: 'All', @@ -9,7 +14,15 @@ const FILTER_TITLES = { [SHOW_MARKED]: 'Completed', }; -export default class Footer extends Component { +interface Props { + markedCount: number; + unmarkedCount: number; + filter: TodoFilter; + onClearMarked: MouseEventHandler; + onShow: (filter: TodoFilter) => void; +} + +export default class Footer extends Component { static propTypes = { markedCount: PropTypes.number.isRequired, unmarkedCount: PropTypes.number.isRequired, @@ -23,7 +36,7 @@ export default class Footer extends Component {