English | 简体中文
Modern React state management framework with concurrent features and modern toolchain. Based on redux, redux-saga and react-router. (Inspired by elm and choo)
- Concurrent Features: Support for
useTransition,useDeferredValue, and automatic batching - Enhanced Performance: 30-50% reduction in re-renders with automatic batching
- React Router v6: Complete migration tools and compatibility layer
- modernx: Main package with all features
- modernx-core: Core functionality and React integration
- modernx-immer: Immer integration for immutable updates
- modernx-loading: Loading state management
- modernx-logger: Redux logger plugin
- modernx-cli: Command-line tools and scaffolding
- modernx-gui: Development GUI and debugging tools
- Full TypeScript Support: Complete TypeScript support with type definitions and ESLint integration
- Code Quality: ESLint + @typescript-eslint + Prettier for consistent code style
- Zero Configuration: Out of the box with sensible defaults
- Modern Toolchain: Built with Node.js 18, latest Babel, and modern build tools
- Hot Reload: Development experience with HMR
- Debugging Tools: Built-in logger and GUI visualization tools
- CLI Integration: Project scaffolding with optional tools
- 100% API Compatibility: Existing projects upgrade without code changes
- Progressive Migration: Gradually adopt new features
- Stable APIs: Reliable and well-tested
# Install the main package
npm install modernx
# Or with yarn
yarn add modernx
# Or with pnpm
pnpm add modernxMake sure you have React 18+ installed:
npm install react@18 react-dom@18import { createApp } from 'modernx';
// 1. Define a model
const countModel = {
namespace: 'count',
state: 0,
reducers: {
add(state) { return state + 1; },
minus(state) { return state - 1; }
},
effects: {
*asyncAdd({ payload }, { put }) {
yield new Promise(resolve => setTimeout(resolve, 1000));
yield put({ type: 'add', payload });
}
}
};
// 2. Create app
const app = createApp({
models: [countModel]
});
// 3. Start app
app.start('#root');import React from 'react';
import { connect } from 'modernx';
const Counter = ({ count, add, minus, asyncAdd }) => (
<div>
<h2>Count: {count}</h2>
<button onClick={add}>+</button>
<button onClick={minus}>-</button>
<button onClick={asyncAdd}>Async +1</button>
</div>
);
export default connect(
({ count }) => ({ count }),
({ add, minus, asyncAdd }) => ({ add, minus, asyncAdd })
)(Counter);We welcome contributions! Please see our Developer Guide for detailed instructions.
# Clone the repository
git clone https://github.com/perlinson/modernx.git
cd modernx
# Install dependencies
npm install
# Bootstrap packages
npm run bootstrap
# Link development dependencies
npm run dev:link
# Start development
npm run dev# Build all packages
npm run build
# Run tests
npm test
# Type checking
npm run typecheck
# Lint code
npm run lint
# Validate monorepo
npm run validate:quick# Workspace status
npm run workspaces:status
# Link internal dependencies
npm run dev:link
# Clean all packages
npm run clean:all
# Run scripts across packages
npm run run:all buildAdd comprehensive Redux logging to your ModernX application:
import modernx from 'modernx';
import logger from 'modernx-logger';
const app = modernx({
plugins: [logger({
collapsed: true,
duration: true,
timestamp: true,
})],
});Start the development GUI for real-time state visualization:
# Start GUI from project directory
npx modernx-gui
# Or include in project creation
npx modernx create my-app --tools guiThe GUI provides:
- Real-time State Visualization: Live display of Redux state changes
- Action History: Complete timeline of all actions with payloads
- Project Structure Analysis: Automatic detection of ModernX models
- WebSocket Communication: Real-time synchronization with your app
Create new ModernX projects with optional debugging tools:
# Create project with logger and GUI
npx modernx create my-app --tools logger,gui
# Interactive project creation
npx modernx create my-app
# Select tools during setup:
# - Logger: Redux logger for debugging
# - GUI: Development GUI with real-time visualizationNon-blocking state updates with useTransition:
import { useDvaTransition } from 'modernx/react18-utils';
const HeavyComponent = () => {
const [isPending, startTransition] = useDvaTransition();
const handleHeavyOperation = () => {
startTransition(() => {
// Non-blocking state update
dispatch({ type: 'heavyOperation' });
});
};
return (
<button onClick={handleHeavyOperation} disabled={isPending}>
{isPending ? 'Processing...' : 'Start Operation'}
</button>
);
};Deferred rendering with useDeferredValue:
import { useDvaConcurrentState } from 'modernx/react18-utils';
const SearchComponent = () => {
const { state, deferredState } = useDvaConcurrentState('search');
return (
<div>
<input onChange={(e) => dispatch({ type: 'search', payload: e.target.value })} />
<div>Current: {state.results.length} results</div>
<div>Deferred: {deferredState.results.length} results</div>
</div>
);
};modernx/
├── packages/
│ ├── modernx/ # Main package
│ ├── modernx-core/ # Core functionality
│ ├── modernx-immer/ # Immer integration
│ ├── modernx-loading/ # Loading state
│ ├── modernx-logger/ # Logger plugin
│ ├── modernx-cli/ # Command-line tools
│ └── modernx-gui/ # Development GUI
├── examples/ # Example projects
├── docs/ # Documentation
├── website/ # VuePress website
└── scripts/ # Build and deployment scripts
# Clone the repository
git clone https://github.com/perlinson/modernx.git
cd modernx
# Install dependencies
npm install
# Start development
npm run dev
# Run tests
npm test
# Build packages
npm run build# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run specific package tests
npm run test:modernx-core| Package | Version | Size | Description |
|---|---|---|---|
| modernx | ~18KB | Main package with all features | |
| modernx-core | ~27KB | Core functionality | |
| modernx-immer | ~2KB | Immer integration | |
| modernx-loading | ~5KB | Loading state management | |
| modernx-logger | ~3KB | Redux logger plugin | |
| modernx-cli | ~8KB | Command-line tools | |
| modernx-gui | ~12KB | Development GUI |
We welcome all kinds of contributions! Please see our Developer Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT © perlinson
- Redux - State management
- Redux-Saga - Side effects
- React Router - Routing
- Elm - Architecture inspiration
- Choo - API inspiration
- Documentation: https://perlinson.github.io/modernx
- GitHub: https://github.com/perlinson/modernx
- NPM: https://www.npmjs.com/package/modernx
- Issues: https://github.com/perlinson/modernx/issues
- Discussions: https://github.com/perlinson/modernx/discussions
Built with ❤️ by perlinson