How dai-shi/react-tracked works
Project type and purpose
• This is an open-source React library (“React Tracked”) that provides “state usage tracking” via Proxies to optimize component re‐renders.
• It ships two core APIs: createContainer (for custom hook containers) and createTrackedSelector (for selectors over Redux, Zustand, etc.).
File structure
• Top-level:
• Configuration & CI: .github/workflows/, vite.config.ts, multiple tsconfig.*.json, package.json, lockfiles, lint/prettier configs.
• Core library: src/ (contains createContainer.ts, createTrackedSelector.ts, index.ts, utils.ts).
• Examples: examples/01_* through examples/15_*—each a standalone minimal React app demonstrating use cases.
• Tests:
– Unit & snapshot tests in tests/ using Vitest.
– E2E tests in tests/e2e/ (Playwright or similar).
• Documentation website: website/—a Docusaurus site with custom modules, docs, pages, and static assets.
README for additional insights
• The README describes the library’s goals, usage patterns (two APIs), integration with React, Redux, Zustand, and notes on React-18 behavior.
• It links to API docs, recipes, tutorials, and examples.
a. Main components
1. Core Library Module
• createContainer API
• createTrackedSelector API
• Core tracking engine (Proxy‐based change detector) in utils.ts
2. Consumer Examples
• 15 example apps showing incremental features—from counter to advanced hooks.
3. Documentation Website
• Docusaurus front end serving markdown docs, API reference, tutorials.
• Custom remark plugin (website/custom_modules/docusaurus-remark-plugin-ts2js).
4. Test Suites
• Unit tests (Vitest)
• E2E tests (Playwright/TS)
5. Build & CI/CD
• Vite build of library and examples
• Vitest workspace setup
• GitHub Actions for CI (lint, tests) and CD (publish to npm, deploy website)
6. External Dependencies
• React, React‐Redux, Zustand, use‐context‐selector, scheduler
b. Relationships & interactions
• The Core Library is the heart; it’s built by Vite, shipped to npm.
• Examples import the built (or local) core library to demonstrate API usage.
• The Documentation Website bundles the library’s API docs and live code samples (often pointing to examples).
• Tests import directly from src/ to validate behavior.
• CI workflows trigger builds, tests, and website deployments upon commits.
• End users consume the published package via npm and integrate with React apps.
c. Architectural patterns & design principles
• Modular layering: Core engine → API wrappers → Consumer code
• Separation of concerns: examples/test/site each in own directory
• Plugin architecture in docs (custom remark plugin)
• Declarative CI/CD pipelines (GitHub Actions)
d. Key technologies & frameworks
• TypeScript + Vite for library building
• Vitest for unit/snapshot testing
• Playwright (or similar) for E2E tests
• Docusaurus v2 for docs website
• React hooks + Proxies for tracking
• GitHub Actions for CI/CD