Hacker News new | ask | show | jobs
LucidJS: a lightweight, dependency-free event emitter library (robertwhurst.github.com)
13 points by godfreykfc 4880 days ago
5 comments

For those looking for more event libraries, try Stapes.js. As a bonus you'll also get class creation and MVC-like get/set with change events:

http://hay.github.com/stapes/#m-mixinEvents

Full disclosure: i'm the author :)

If you are using jQuery and just need a simple generic event emitter, you may not need this library.

    var emitter = jQuery({});
    emitter.on('ready', function() { alert("Ready!"); });
    emitter.trigger('ready');
...or if you're on Node, Node.js already has API for events:

    var EventEmitter = require('events').EventEmitter;

    var emitter = new EventEmitter();
    emitter.on('ready', function() { alert("Ready!"); });
    emitter.trigger('ready');
The reason you'd use LucidJS is for its other features that these solutions don't have, like `.set()` and `.pipe()`.
The author did a talk at VanJS today, and he compared LucidJS with other events library[1]. From what I got out of it, besides the nice features it offers (set/pipe/etc), this is probably most useful for people who would like to release a library/JS API without depending on one of the "heavier" frameworks - for example, libraries like History.js would be able to use LucidJS as the events library instead of coupling with something like jQuery or rolling their own.

[1]: http://lucidjs.harp.io/#slide-30

It might be nice to register on component(1) registry. https://github.com/component/component/wiki/Components
Since its not stated anywhere that I could see, and I wanted to see its 'lightweightness'...minified it is 8.9k and gzipped it is 2.3k
Can someone give me a basic explanation/examples of the use cases of event emitters?