Skip to content

vitalii4reva/visual-js-event-loop

Repository files navigation

JavaScript Event Loop Visualizer πŸ”„

An interactive tool for visualizing and learning JavaScript Event Loop principles. Modern React web application with beautiful UI that helps developers understand JavaScript asynchronicity, execution order, and interaction between Call Stack, Web APIs, Microtask and Task (Callback) queues.

JavaScript Event Loop Visualizer

Live Demo License: MIT React TypeScript

πŸ‡ΊπŸ‡¦ Π£ΠΊΡ€Π°Ρ—Π½ΡΡŒΠΊΠ° вСрсія

✨ Features

🎨 UI/UX

  • Modern design with shadcn/ui components and responsive sidebar
  • Dark and light theme with automatic switching
  • Fully responsive design for mobile, tablets and desktops
  • Smart sidebar:
    • Automatically collapses on narrow screens (icons only)
    • Expands on wide screens with full text
    • Toggle with B key
  • Smooth animations and state transitions
  • Intuitive interface with tooltips and hints
  • Clean UI - empty sections auto-hide

πŸ“š Functionality

  • Visualization of Call Stack, Web APIs, Microtask Queue, Task Queue, Stack and Heap memory
  • Step-by-step execution with detailed explanations for each action
  • 5 built-in examples:
    • πŸ—„οΈ Memory and Variables - Stack and Heap demonstration (primitives, objects, functions)
    • ⏱️ setTimeout - basic async code handling
    • ⚑ Promise vs setTimeout - difference between microtask and macrotask
    • πŸ”„ Complex Example - nested Promises and setTimeout
    • 🌐 Fetch API - network requests and handling
  • Two execution modes: automatic and manual
  • Action history to track all execution steps
  • Code display with active line highlighting
  • Interactive sidebar with:
    • Quick example launch
    • Clear buttons (full and selective)
    • Event Loop reference guide
  • Keyboard shortcuts: Space, 0-4, A, B, C, Esc for quick navigation

🌍 Localization

  • English (default, auto-detected from browser)
  • Ukrainian (ΠΏΠΎΠ²Π½Π° ΠΏΡ–Π΄Ρ‚Ρ€ΠΈΠΌΠΊΠ° ΡƒΠΊΡ€Π°Ρ—Π½ΡΡŒΠΊΠΎΡ— ΠΌΠΎΠ²ΠΈ)
  • Language switcher in the header for instant language switching
  • Language preference persists across page reloads (localStorage)
  • All interface elements, examples, and explanations are fully translated

πŸš€ Quick Start

Prerequisites

  • Node.js 18.0.0+ (recommended 20+)
  • pnpm (recommended) or npm

Installation

# Clone the repository
git clone https://github.com/vitalii4reva/visual-js-event-loop.git
cd visual-js-event-loop

# Install dependencies
pnpm install

# Start dev server
pnpm dev

Open http://localhost:3000 in your browser.

Production Build

# Create production build
pnpm build

# Preview production version locally
pnpm preview

Build output will be in the dist/ directory

πŸ—οΈ Technologies

  • βš›οΈ React 19 - UI framework
  • πŸ“˜ TypeScript 5.9 - Type safety
  • 🎨 Tailwind CSS 3.4 - Styling
  • 🧩 shadcn/ui - UI components
  • ⚑ Vite 6 - Build tool
  • 🎭 Lucide React - Icons
  • πŸŒ“ next-themes - Theme management

πŸ“‚ Project Structure

src/
β”œβ”€β”€ components/          # React components
β”‚   β”œβ”€β”€ ui/             # shadcn/ui components (sidebar, button, card...)
β”‚   β”œβ”€β”€ layout/         # Header, ExamplesSidebar, KeyboardShortcuts
β”‚   β”œβ”€β”€ event-loop/     # Event Loop Visualization
β”‚   β”‚   β”œβ”€β”€ CallStack.tsx
β”‚   β”‚   β”œβ”€β”€ WebAPIs.tsx
β”‚   β”‚   β”œβ”€β”€ MicrotaskQueue.tsx
β”‚   β”‚   β”œβ”€β”€ TaskQueue.tsx
β”‚   β”‚   β”œβ”€β”€ Memory.tsx         # Heap memory
β”‚   β”‚   └── StackVariables.tsx # Stack frames
β”‚   β”œβ”€β”€ controls/       # StepControls
β”‚   └── panels/         # HistoryPanel
β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”œβ”€β”€ useEventLoop.ts
β”‚   β”œβ”€β”€ useStepExecution.ts
β”‚   β”œβ”€β”€ useKeyboardShortcuts.ts
β”‚   └── use-mobile.tsx
β”œβ”€β”€ context/            # React Context (ThemeProvider, LanguageProvider)
β”œβ”€β”€ lib/                # Utilities and examples
β”‚   β”œβ”€β”€ examples.ts     # 5 built-in examples
β”‚   └── utils.ts
β”œβ”€β”€ types/              # TypeScript types
β”‚   β”œβ”€β”€ eventLoop.ts
β”‚   └── memory.ts
β”œβ”€β”€ i18n/               # Translations (en, uk)
β”œβ”€β”€ App.tsx             # Main component
└── main.tsx            # Entry point

πŸ”§ How It Works

The visualizer demonstrates JavaScript Event Loop operation and memory management:

  1. Call Stack: Shows functions currently executing.
  2. Web APIs: Displays asynchronous operations running in background.
  3. Microtask Queue: High-priority task queue (Promise).
  4. Task Queue: Regular task queue (setTimeout, setInterval).
  5. Stack Variables: Shows local variables in Stack Frames.
  6. Memory (Heap): Shows objects, functions, and other complex data types.
  7. Event Loop: Constantly checks stack and queue state, following priorities.

Event Loop Execution Order:

  1. Execute all synchronous code in Call Stack
  2. Check if Call Stack is empty
  3. Process ALL microtasks from Microtask Queue
  4. Take ONE task from Task Queue
  5. Repeat from step 1

🎯 How to Use

  1. Select an example in the left sidebar (or keys 0-4):
    • 0 - Memory and Variables (Stack & Heap)
    • 1 - setTimeout demonstration
    • 2 - Promise vs setTimeout
    • 3 - Complex example
    • 4 - Fetch API
  2. Execution mode:
    • Manual mode: Click "Next step" or Space/Enter
    • Auto mode: Automatic execution with 1.5 sec delay (key A)
  3. Observe:
    • Call Stack - active functions
    • Web APIs - asynchronous operations
    • Microtask Queue - high-priority tasks (Promise)
    • Task Queue - regular tasks (setTimeout)
    • Memory (Heap) - objects and functions (appear in example 0)
  4. Track action history in the right panel
  5. Control sidebar - key B or button in header
  6. Keyboard shortcuts - Click keyboard icon in header for full list

πŸ‘₯ Contributing

We encourage contributions to the project!

Ways to Help

  • πŸ› Report a bug via Issues
  • ✨ Suggest a new feature
  • πŸ“ Improve documentation
  • 🌍 Add translation to another language
  • πŸ’» Submit a Pull Request

Process

  1. Fork the repository
  2. Create a branch: git checkout -b feature/amazing-feature
  3. Make changes and commit: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ’‘ Improvement ideas

  • Add Examples 3 and 4 (complex example, Fetch API) βœ…
  • Keyboard shortcuts (Space, numbers, A, C) βœ…
  • Responsive sidebar with shadcn/ui βœ…
  • Stack and Heap memory visualization βœ…
  • Memory example βœ…
  • Multi-language support (EN, UK) βœ…
  • Interactive mode for creating custom examples
  • Export execution history
  • Additional languages (PL, etc.)
  • Animations with Framer Motion
  • Touch gestures for mobile

πŸ“ˆ SEO and Performance

Project is optimized for search engines:

  • βœ… Structured Data (JSON-LD) with author information
  • βœ… Open Graph tags for social networks
  • βœ… Meta tags for search engines
  • βœ… Responsive Design
  • βœ… Performance optimization
  • βœ… Accessibility (ARIA labels)
  • βœ… Humans.txt and Robots.txt
  • βœ… Sitemap.xml

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Vitalii Petrenko

πŸ™ Acknowledgments

  • React for an amazing UI framework
  • shadcn/ui for beautiful components
  • Vite for a fast build tool
  • Lucide for quality icons

If this project was helpful, give it a ⭐ on GitHub!

Made with ❀️ in Ukraine πŸ‡ΊπŸ‡¦

⬆ Back to top

About

JavaScript Event Loop Visualizer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors