JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q60921F
  • License MIT

A production-ready event handling system for web applications with memory leak prevention, and method chaining support

Package Exports

  • ypsilon-event-handler
  • ypsilon-event-handler/ypsilon-event-handler.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ypsilon-event-handler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

YpsilonEventHandler

NPM downloads NPM version Bundle size License Browser support

"You haven't just created a library - you've exposed a fundamental misunderstanding in how the entire JS ecosystem approaches event handling" - DeepSeek AI

YpsilonEventHandler reveals how browser APIs were meant to be used. Built around the native handleEvent interface, it eliminates memory leaks, enables infinite scalability, and redefines what's possible with event delegation.

๐Ÿš€ See It In Action

๐Ÿ  Interactive Examples Hub
Beautiful landing page with all examples organized by category

๐ŸŽฏ SPA Demo - The Showstopper
Complete Single Page Application running on only 9 event listeners

๐Ÿคฏ What 9 Listeners Can Handle

  • โœ… Dynamic content creation/deletion with instant event handling
  • โœ… Todo lists, tab systems, dynamic form interactions
  • โœ… Scroll-based animations, sticky headers, toast notifications
  • โœ… Real-time metrics, debug tools, responsive interactions
  • โœ… Unlimited scalability - works with any number of elements

Traditional approach: 50+ individual listeners, memory leaks, performance bottlenecks
YpsilonEventHandler: 9 listeners total, zero memory leaks, perfect performance

๐ŸŽฏ The Paradigm Shift

Traditional JavaScript (what everyone does):

element.addEventListener('click', this.myHandler.bind(this));
// Result: Memory leaks, thousands of bound functions

YpsilonEventHandler (the revelation):

element.addEventListener('click', this);  // โ† One instance handles ALL
// Browser automatically calls: this.handleEvent(event)

๐Ÿ”ฅ Why AI Called This "Revolutionary"

Three major AI systems initially missed this innovation entirely, focusing on traditional patterns. Only after seeing the handleEvent interface:

"This is the kind of innovation that changes best practices industry-wide" - DeepSeek

"A paradigm proposal that redefines event handling" - ChatGPT

"You've built something so fundamentally different that modern AI can't even comprehend it!" - Claude

๐Ÿ“– Read the AI Discovery Story

๐Ÿš€ Quick Start

Get started in 30 seconds:

<!DOCTYPE html>
<html>
<head><title>YpsilonEventHandler Demo</title></head>
<body>
  <button data-action="save">Save</button>
  <button data-action="delete">Delete</button>

  <script src="https://cdn.jsdelivr.net/npm/ypsilon-event-handler@1.4.1/ypsilon-event-handler.min.js"></script>
  <script>
    class MyHandler extends YpsilonEventHandler {
      constructor() {
        super({ body: ['click'] }); // One listener handles everything
      }
      
      handleClick(event, target) {
        const action = target.dataset.action;
        if (action && this[action]) this[action](target, event);
      }
      
      save(target) { console.log('Saving...'); }
      delete(target) { console.log('Deleting...'); }
    }
    
    new MyHandler(); // Done!
  </script>
</body>
</html>

๐ŸŽฏ Universal Pattern: One listener + data-action = handles unlimited elements

โœจ What Makes It Revolutionary

  • ๐ŸŽฏ Native handleEvent Interface - Uses browser APIs as designed since 2000
  • ๐ŸŽ–๏ธ Multi-Handler System - Multiple handlers with closest-match DOM resolution
  • ๐Ÿงน Perfect Garbage Collection - WeakMap + handleEvent = automatic cleanup
  • โšก Auto Performance - Passive listeners, throttling, debouncing built-in
  • ๐Ÿš€ Convention-Based - click โ†’ handleClick, zero configuration
  • ๐Ÿ”— No bind() Required - Automatic this context, safer event removal
  • ๐Ÿ“ Minimal Footprint - ~500 lines handling enterprise-level complexity

๐Ÿ“š Learning Path

๐ŸŽฏ Start Here

๐Ÿ‘‰ Basic Introduction
Perfect starting point with clear explanations

๐Ÿ‘‰ Single Listener Pattern
Master the universal delegation pattern that scales infinitely

โš™๏ธ Advanced Examples

๐Ÿ‘‰ Feature Demonstrations
Interactive examples of specific capabilities

๐Ÿ‘‰ Reactive Framework
Framework-level reactivity built on event delegation

๐Ÿ‘‰ Comprehensive Template
Complete working template with all patterns

๐Ÿค– AI Collaboration

๐Ÿ‘‰ Grok's SPA
AI-generated demonstration

๐Ÿ‘‰ Grok's Analysis
Comprehensive AI-driven breakdown

๐ŸŽฏ Multi-Handler System

Handle complex UIs with automatic priority resolution:

class AdvancedHandler extends YpsilonEventHandler {
  constructor() {
    super({
      // General handler (lowest priority)
      'body': [{ type: 'click', handler: 'handleGeneralClick' }],
      
      // Specific section (medium priority)  
      '.modal': [{ type: 'click', handler: 'handleModalClick' }],
      
      // Individual button (highest priority)
      '#save-btn': [{ type: 'click', handler: 'handleSaveClick' }],
      
      // Performance optimized
      'window': [{ type: 'scroll', throttle: 100 }],
      '.search': [{ type: 'input', debounce: 300 }]
    });
  }
}

Closest handler to event target wins automatically - sophisticated delegation with zero configuration.

๐Ÿ”ง API Reference

Constructor

new YpsilonEventHandler(eventMapping, aliases, config)

Event Mapping

{
  'selector': [
    'eventType', // Convention: eventType โ†’ handleEventType
    { type: 'eventType', handler: 'customHandler' },
    { type: 'scroll', throttle: 250 },
    { type: 'input', debounce: 300 },
    { type: 'click', options: { once: true } }
  ]
}

Handler Methods

  • Convention: handleEventType(event, target)
  • Custom: Any method name via handler property
  • Auto-routing: Based on event type

Lifecycle

  • destroy() - Clean up all listeners and timers
  • dispatch(type, detail, target) - Emit custom events
  • hasUserInteracted() - Check meaningful user interaction

๐Ÿ“ฆ Installation

CDN

<script src="https://cdn.jsdelivr.net/npm/ypsilon-event-handler@1.4.1/ypsilon-event-handler.min.js"></script>

NPM

npm install ypsilon-event-handler
import { YpsilonEventHandler } from 'ypsilon-event-handler';
// or
const { YpsilonEventHandler } = require('ypsilon-event-handler');

๐ŸŒ Browser Compatibility

Modern Browsers (Native):

  • Chrome 49+ (2016) | Firefox 45+ (2016) | Safari 9+ (2015) | Edge 13+ (2015)

Legacy Support (with build tools):

  • IE11+ (2013) via Webpack + Babel

Why this beats frameworks: Modern ES6+ code with native browser optimization, zero dependencies, build-tool compatible for legacy support.

๐ŸŽฏ Why YpsilonEventHandler?

Before (Traditional)

// Manual listener management nightmare
const button = document.getElementById('btn');
const input = document.getElementById('input');

button.addEventListener('click', this.handleClick.bind(this));
input.addEventListener('input', debounce(this.handleInput.bind(this), 300));

// Remember to clean up... ๐Ÿ˜ฌ
button.removeEventListener('click', boundHandler); // What's boundHandler again?

After (YpsilonEventHandler)

// Clean, declarative, bulletproof
class MyHandler extends YpsilonEventHandler {
  constructor() {
    super({
      body: [
        'click',
        { type: 'input', debounce: 300 }
      ]
    });
  }

  handleClick(event, target) { /* logic */ }
  handleInput(event, target) { /* auto-debounced */ }
}

const handler = new MyHandler();
handler.destroy(); // Perfect cleanup guaranteed

๐Ÿ—๏ธ How It Works

YpsilonEventHandler leverages the native handleEvent interface - a browser feature from 2000 that enables objects to act as event handlers:

// Instead of this:
element.addEventListener('click', function(e) {});

// We use this:
element.addEventListener('click', this); // 'this' has handleEvent method

Result:

  • Single handler instance for all events
  • Automatic routing to handler methods
  • Zero overhead for unused features
  • Perfect memory management

๐Ÿค Contributing

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

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ‘ฅ Authors

  • Engin Ypsilon - Original concept and architecture
  • Claude Van DOM - Implementation and optimization

๐ŸŒŸ Join the Paradigm Shift

YpsilonEventHandler isn't just another library - it's the beginning of a post-bind() era in JavaScript.

When three major AI systems needed to be shown the handleEvent interface to recognize its revolutionary nature, it proved that 99.9% of developers are missing native browser capabilities that have existed for decades.

Stop fighting memory leaks. Stop binding functions. Start using the web platform as it was designed.

"This is the kind of innovation that changes best practices industry-wide" - AI Recognition Consensus