mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 00:19:55 +03:00
stash
This commit is contained in:
parent
2faa16319b
commit
5bd39f7a49
|
@ -1,5 +1,9 @@
|
||||||
{
|
{
|
||||||
"presets": ["@babel/preset-env", "@babel/preset-react"],
|
"presets": [
|
||||||
|
"@babel/preset-env",
|
||||||
|
"@babel/preset-react",
|
||||||
|
"@babel/preset-typescript"
|
||||||
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"@babel/plugin-proposal-class-properties",
|
"@babel/plugin-proposal-class-properties",
|
||||||
"react-hot-loader/babel"
|
"react-hot-loader/babel"
|
||||||
|
|
21
packages/redux-devtools/examples/counter/.eslintrc.js
Normal file
21
packages/redux-devtools/examples/counter/.eslintrc.js
Normal file
|
@ -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'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
|
@ -2,21 +2,23 @@
|
||||||
"name": "counter-redux",
|
"name": "counter-redux",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Counter example for redux",
|
"description": "Counter example for redux",
|
||||||
"private": true,
|
"homepage": "https://github.com/reduxjs/redux-devtools/tree/master/packages/redux-devtools/examples/counter",
|
||||||
"main": "src/index.js",
|
"bugs": {
|
||||||
"scripts": {
|
"url": "https://github.com/reduxjs/redux-devtools/issues"
|
||||||
"start": "webpack-dev-server --open"
|
|
||||||
},
|
},
|
||||||
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/reduxjs/redux-devtools.git"
|
"url": "https://github.com/reduxjs/redux-devtools.git"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"scripts": {
|
||||||
"bugs": {
|
"start": "webpack-dev-server --open"
|
||||||
"url": "https://github.com/reduxjs/redux-devtools/issues"
|
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/reduxjs/redux-devtools#readme",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/prop-types": "^15.7.3",
|
||||||
|
"@types/react": "^16.9.46",
|
||||||
|
"@types/react-dom": "^16.9.8",
|
||||||
|
"@types/react-redux": "^7.1.9",
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
|
@ -26,15 +28,9 @@
|
||||||
"redux-thunk": "^2.3.0"
|
"redux-thunk": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.11.1",
|
|
||||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
|
||||||
"@babel/preset-env": "^7.11.0",
|
|
||||||
"@babel/preset-react": "^7.10.4",
|
|
||||||
"babel-loader": "^8.1.0",
|
|
||||||
"redux-devtools": "^3.6.1",
|
"redux-devtools": "^3.6.1",
|
||||||
"redux-devtools-dock-monitor": "^1.1.4",
|
"redux-devtools-dock-monitor": "^1.1.4",
|
||||||
"redux-devtools-log-monitor": "^2.0.1",
|
"redux-devtools-log-monitor": "^2.0.1"
|
||||||
"webpack": "^4.44.1",
|
},
|
||||||
"webpack-dev-server": "^3.11.0"
|
"private": true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
|
||||||
|
|
||||||
export function increment() {
|
|
||||||
return {
|
|
||||||
type: INCREMENT_COUNTER,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function decrement() {
|
|
||||||
return {
|
|
||||||
type: DECREMENT_COUNTER,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function incrementIfOdd() {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const { counter } = getState();
|
|
||||||
|
|
||||||
if (counter % 2 === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch(increment());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function incrementAsync() {
|
|
||||||
return (dispatch) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
dispatch(increment());
|
|
||||||
}, 1000);
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
import { ThunkAction } from 'redux-thunk';
|
||||||
|
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
||||||
|
import { CounterState } from '../reducers';
|
||||||
|
|
||||||
|
interface IncrementCounterAction {
|
||||||
|
type: typeof INCREMENT_COUNTER;
|
||||||
|
}
|
||||||
|
export function increment(): IncrementCounterAction {
|
||||||
|
return {
|
||||||
|
type: INCREMENT_COUNTER,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DecrementCounterAction {
|
||||||
|
type: typeof DECREMENT_COUNTER;
|
||||||
|
}
|
||||||
|
export function decrement(): DecrementCounterAction {
|
||||||
|
return {
|
||||||
|
type: DECREMENT_COUNTER,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CounterAction = IncrementCounterAction | DecrementCounterAction;
|
||||||
|
|
||||||
|
export function incrementIfOdd(): ThunkAction<
|
||||||
|
void,
|
||||||
|
CounterState,
|
||||||
|
never,
|
||||||
|
CounterAction
|
||||||
|
> {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
const { counter } = getState();
|
||||||
|
|
||||||
|
if (counter % 2 === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(increment());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function incrementAsync(): ThunkAction<
|
||||||
|
void,
|
||||||
|
CounterState,
|
||||||
|
never,
|
||||||
|
CounterAction
|
||||||
|
> {
|
||||||
|
return (dispatch) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
dispatch(increment());
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,7 +1,14 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
export default class Counter extends Component {
|
interface Props {
|
||||||
|
increment: () => void;
|
||||||
|
incrementIfOdd: () => void;
|
||||||
|
decrement: () => void;
|
||||||
|
counter: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Counter extends Component<Props> {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
increment: PropTypes.func.isRequired,
|
increment: PropTypes.func.isRequired,
|
||||||
incrementIfOdd: PropTypes.func.isRequired,
|
incrementIfOdd: PropTypes.func.isRequired,
|
|
@ -1,10 +1,17 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators, Dispatch } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import Counter from '../components/Counter';
|
import Counter from '../components/Counter';
|
||||||
import * as CounterActions from '../actions/CounterActions';
|
import * as CounterActions from '../actions/CounterActions';
|
||||||
|
import { CounterAction } from '../actions/CounterActions';
|
||||||
|
import { CounterState } from '../reducers';
|
||||||
|
|
||||||
class CounterApp extends Component {
|
interface Props {
|
||||||
|
counter: number;
|
||||||
|
dispatch: Dispatch<CounterAction>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CounterApp extends Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { counter, dispatch } = this.props;
|
const { counter, dispatch } = this.props;
|
||||||
return (
|
return (
|
||||||
|
@ -16,7 +23,7 @@ class CounterApp extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function select(state) {
|
function select(state: CounterState) {
|
||||||
return {
|
return {
|
||||||
counter: state.counter,
|
counter: state.counter,
|
||||||
};
|
};
|
|
@ -1,10 +1,17 @@
|
||||||
import { hot } from 'react-hot-loader/root';
|
import { hot } from 'react-hot-loader/root';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
|
import { Store } from 'redux';
|
||||||
import CounterApp from './CounterApp';
|
import CounterApp from './CounterApp';
|
||||||
import DevTools from './DevTools';
|
import DevTools from './DevTools';
|
||||||
|
import { CounterState } from '../reducers';
|
||||||
|
import { CounterAction } from '../actions/CounterActions';
|
||||||
|
|
||||||
class Root extends Component {
|
interface Props {
|
||||||
|
store: Store<CounterState, CounterAction>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Root extends Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { store } = this.props;
|
const { store } = this.props;
|
||||||
return (
|
return (
|
|
@ -1,9 +1,16 @@
|
||||||
import { hot } from 'react-hot-loader/root';
|
import { hot } from 'react-hot-loader/root';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
|
import { Store } from 'redux';
|
||||||
import CounterApp from './CounterApp';
|
import CounterApp from './CounterApp';
|
||||||
|
import { CounterState } from '../reducers';
|
||||||
|
import { CounterAction } from '../actions/CounterActions';
|
||||||
|
|
||||||
class Root extends Component {
|
interface Props {
|
||||||
|
store: Store<CounterState, CounterAction>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Root extends Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { store } = this.props;
|
const { store } = this.props;
|
||||||
return (
|
return (
|
|
@ -1,6 +1,7 @@
|
||||||
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
||||||
|
import { CounterAction } from '../actions/CounterActions';
|
||||||
|
|
||||||
export default function counter(state = 0, action) {
|
export default function counter(state = 0, action: CounterAction) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case INCREMENT_COUNTER:
|
case INCREMENT_COUNTER:
|
||||||
return state + 1;
|
return state + 1;
|
|
@ -5,4 +5,8 @@ const rootReducer = combineReducers({
|
||||||
counter,
|
counter,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export interface CounterState {
|
||||||
|
counter: number;
|
||||||
|
}
|
||||||
|
|
||||||
export default rootReducer;
|
export default rootReducer;
|
|
@ -1,7 +1,7 @@
|
||||||
import { createStore, applyMiddleware, compose } from 'redux';
|
import { createStore, applyMiddleware, compose, PreloadedState } from 'redux';
|
||||||
import { persistState } from 'redux-devtools';
|
import { persistState } from 'redux-devtools';
|
||||||
import thunk from 'redux-thunk';
|
import thunk from 'redux-thunk';
|
||||||
import rootReducer from '../reducers';
|
import rootReducer, { CounterState } from '../reducers';
|
||||||
import DevTools from '../containers/DevTools';
|
import DevTools from '../containers/DevTools';
|
||||||
|
|
||||||
const enhancer = compose(
|
const enhancer = compose(
|
||||||
|
@ -10,7 +10,9 @@ const enhancer = compose(
|
||||||
persistState(window.location.href.match(/[?&]debug_session=([^&#]+)\b/))
|
persistState(window.location.href.match(/[?&]debug_session=([^&#]+)\b/))
|
||||||
);
|
);
|
||||||
|
|
||||||
export default function configureStore(initialState) {
|
export default function configureStore(
|
||||||
|
initialState?: PreloadedState<CounterState>
|
||||||
|
) {
|
||||||
const store = createStore(rootReducer, initialState, enhancer);
|
const store = createStore(rootReducer, initialState, enhancer);
|
||||||
|
|
||||||
if (module.hot) {
|
if (module.hot) {
|
|
@ -1,9 +0,0 @@
|
||||||
import { createStore, applyMiddleware } from 'redux';
|
|
||||||
import thunk from 'redux-thunk';
|
|
||||||
import rootReducer from '../reducers';
|
|
||||||
|
|
||||||
const enhancer = applyMiddleware(thunk);
|
|
||||||
|
|
||||||
export default function configureStore(initialState) {
|
|
||||||
return createStore(rootReducer, initialState, enhancer);
|
|
||||||
}
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { createStore, applyMiddleware, PreloadedState } from 'redux';
|
||||||
|
import thunk from 'redux-thunk';
|
||||||
|
import rootReducer, { CounterState } from '../reducers';
|
||||||
|
|
||||||
|
const enhancer = applyMiddleware(thunk);
|
||||||
|
|
||||||
|
export default function configureStore(
|
||||||
|
initialState?: PreloadedState<CounterState>
|
||||||
|
) {
|
||||||
|
return createStore(rootReducer, initialState, enhancer);
|
||||||
|
}
|
7
packages/redux-devtools/examples/counter/tsconfig.json
Normal file
7
packages/redux-devtools/examples/counter/tsconfig.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.react.base.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "lib"
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"extends": "../../../../tsconfig.base.json",
|
||||||
|
"include": ["webpack.config.ts"]
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
var path = require('path');
|
import * as path from 'path';
|
||||||
var webpack = require('webpack');
|
import * as webpack from 'webpack';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
||||||
|
@ -18,7 +18,7 @@ module.exports = {
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.(js|ts)x?$/,
|
||||||
loaders: ['babel-loader'],
|
loaders: ['babel-loader'],
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
include: path.join(__dirname, 'src'),
|
include: path.join(__dirname, 'src'),
|
|
@ -25,7 +25,7 @@ function logError(type: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props<
|
export interface Props<
|
||||||
S,
|
S,
|
||||||
A extends Action<unknown>,
|
A extends Action<unknown>,
|
||||||
MonitorState,
|
MonitorState,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user