How to Use It
You need a single file microevent.js. Include it in a webpage via the usual script tag.
To include it in a nodejs code isnt much harder
Now suppose you got a class
Foobar, and you wish it to support the observer partern. do
First we define the class which going to use MicroEvent.js. This is a ticker, it is triggering ‘tick’ events every second, and add the current date as parameter
1 2 3 4 5 6
We mixin MicroEvent into Ticker and we are all set.
Now lets actually use the Ticker Class. First, create the object.
and bind our tick event with its data parameter
1 2 3
And you will see this output:
notified date Tue, 22 Mar 2011 14:43:41 GMT notified date Tue, 22 Mar 2011 14:43:42 GMT ...
I needed a event emitter in js… something generic which works on browser and server, cross browser. The solutions i found were too complex for my taste.
When i have seen John Resig micro templating or simple inheritance, i loved it. It is simple, short, self contained, easy to understand… so elegant. i thought “this is no more a dependancy because i could maintain it if needed”. Now i try to apply those principles to my own work.