Bean: Framework-Agnostic Event Manager

1.0.15 · abandoned · verified Tue Apr 21

Bean is a small, fast, and framework-agnostic event manager designed for desktop, mobile, and touch-based browsers, originating from an earlier era of web development (circa 2010-2012). The current stable version is 1.0.15, which was released over a decade ago. The project is no longer actively maintained or developed, making it an abandoned package. It offered a concise API for event handling, including `on`, `one`, `off`, `clone`, and `fire`, along with support for event delegation and namespacing. A key differentiator was its standalone nature, providing event management capabilities without the overhead of larger JavaScript libraries like jQuery.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic event attachment, event delegation using a CSS selector, namespaced events, firing events, and detaching event handlers using the `bean` API.

const bean = require('bean');

const button = document.createElement('button');
button.textContent = 'Click me';
document.body.appendChild(button);

bean.on(button, 'click', function (e) {
  console.log('Button clicked!', e.type, e.target);
});

const delegatedContainer = document.createElement('div');
delegatedContainer.id = 'container';
document.body.appendChild(delegatedContainer);

const paragraph1 = document.createElement('p');
paragraph1.className = 'content-item';
paragraph1.textContent = 'Paragraph 1';
delegatedContainer.appendChild(paragraph1);

const paragraph2 = document.createElement('p');
paragraph2.className = 'content-item';
paragraph2.textContent = 'Paragraph 2';
delegatedContainer.appendChild(paragraph2);

bean.on(delegatedContainer, 'click', '.content-item', function (e) {
  console.log('Delegated click on:', e.target.textContent);
});

// Example of namespaced event
bean.on(button, 'mouseover.highlight', function() {
  console.log('Button mouseover (namespaced)');
});

// Fire a namespaced event
setTimeout(() => {
  bean.fire(button, 'mouseover.highlight');
}, 1000);

// Clean up an event
setTimeout(() => {
  bean.off(button, 'click');
  console.log('Click handler removed from button.');
}, 2000);

view raw JSON →