Ultron is a high-intelligence robot. It gathers intelligence so it can start improving upon his rudimentary design. It will learn your event emitting patterns and find ways to exterminate them. Allowing you to remove only the event emitters that you assigned and not the ones that your users or developers assigned. This can prevent race conditions, memory leaks and even file descriptor leaks from ever happening as you won't remove clean up processes.
The module is designed to be used in browsers using browserify and in Node.js. You can install the module through the public npm registry by running the following command in CLI:
npm install --save ultron
In all examples we assume that you've required the library as following:
'use strict';var Ultron = ;
Now that we've required the library we can construct our first
The constructor requires one argument which should be the
instance that we need to operate upon. This can be the
that ships with Node.js or
EventEmitter3 or anything else as long as it
follow the same API and internal structure as these 2. So with that in mind we
can create the instance:
//// For the sake of this example we're going to construct an empty EventEmitter//var EventEmitter = EventEmitter; // or require('eventmitter3');var events = ;var ultron = events;
You can now use the following API's from the Ultron instance:
Register a new event listener for the given event. It follows the exact same API
EventEmitter.on but it will return itself instead of returning the
EventEmitter instance. If you are using EventEmitter3 it also supports the
Exactly the same as the Ultron.on but it only allows the execution once.
This is where all the magic happens and the safe removal starts. This function accepts different argument styles:
,to create a list of events that need to be cleared.
ultron; // Removes foo, bar and baz.ultron; // Removes foo, bar and baz.ultron; // Removes everything.
If you just want to remove a single event listener using a function reference
you can still use the EventEmitter's
removeListener(event, fn) API: