From 6cd1e85a69418d8031762801c122298019ee5f41 Mon Sep 17 00:00:00 2001 From: Jared K. Smith Date: Dec 14 2017 16:20:44 +0000 Subject: Update to upstream 1.1.1 release --- diff --git a/.gitignore b/.gitignore index 753bbcd..490978e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /ultron-1.0.1.tgz /ultron-1.1.0.tgz +/ultron-1.1.1.tgz diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9d8b07 --- /dev/null +++ b/README.md @@ -0,0 +1,113 @@ +# Ultron + +[![Made by unshift](https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square)](http://unshift.io)[![Version npm](http://img.shields.io/npm/v/ultron.svg?style=flat-square)](http://browsenpm.org/package/ultron)[![Build Status](http://img.shields.io/travis/unshiftio/ultron/master.svg?style=flat-square)](https://travis-ci.org/unshiftio/ultron)[![Dependencies](https://img.shields.io/david/unshiftio/ultron.svg?style=flat-square)](https://david-dm.org/unshiftio/ultron)[![Coverage Status](http://img.shields.io/coveralls/unshiftio/ultron/master.svg?style=flat-square)](https://coveralls.io/r/unshiftio/ultron?branch=master)[![IRC channel](http://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square)](http://webchat.freenode.net/?channels=unshift) + +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. + +## Installation + +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 +``` + +## Usage + +In all examples we assume that you've required the library as following: + +```js +'use strict'; + +var Ultron = require('ultron'); +``` + +Now that we've required the library we can construct our first `Ultron` instance. +The constructor requires one argument which should be the `EventEmitter` +instance that we need to operate upon. This can be the `EventEmitter` module +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: + +```js +// +// For the sake of this example we're going to construct an empty EventEmitter +// +var EventEmitter = require('events').EventEmitter; // or require('eventmitter3'); +var events = new EventEmitter(); + +var ultron = new Ultron(events); +``` + +You can now use the following API's from the Ultron instance: + +### Ultron.on + +Register a new event listener for the given event. It follows the exact same API +as `EventEmitter.on` but it will return itself instead of returning the +EventEmitter instance. If you are using EventEmitter3 it also supports the +context param: + +```js +ultron.on('event-name', handler, { custom: 'function context' }); +``` + +Just like you would expect, it can also be chained together. + +```js +ultron +.on('event-name', handler) +.on('another event', handler); +``` + +### Ultron.once + +Exactly the same as the [Ultron.on](#ultronon) but it only allows the execution +once. + +Just like you would expect, it can also be chained together. + +```js +ultron +.once('event-name', handler, { custom: 'this value' }) +.once('another event', handler); +``` + +### Ultron.remove + +This is where all the magic happens and the safe removal starts. This function +accepts different argument styles: + +- No arguments, assume that all events need to be removed so it will work as + `removeAllListeners()` API. +- 1 argument, when it's a string it will be split on ` ` and `,` to create a + list of events that need to be cleared. +- Multiple arguments, we assume that they are all names of events that need to + be cleared. + +```js +ultron.remove('foo, bar baz'); // Removes foo, bar and baz. +ultron.remove('foo', 'bar', 'baz'); // Removes foo, bar and baz. +ultron.remove(); // 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: + +```js +function foo() {} + +ultron.on('foo', foo); +events.removeListener('foo', foo); +``` + +## License + +MIT diff --git a/nodejs-ultron.spec b/nodejs-ultron.spec index c40d116..0ad2b86 100644 --- a/nodejs-ultron.spec +++ b/nodejs-ultron.spec @@ -7,7 +7,7 @@ Summary: Ultron is a high-intelligence robot Name: nodejs-%{npm_name} -Version: 1.1.0 +Version: 1.1.1 Release: 1%{?dist} License: MIT URL: https://github.com/unshiftio/ultron @@ -61,6 +61,9 @@ mocha --reporter spec --ui bdd test.js %{nodejs_sitelib}/%{npm_name} %changelog +* Thu Dec 14 2017 Jared Smith - 1.1.1-1 +- Update to upstream 1.1.1 release + * Tue Sep 19 2017 Jared Smith - 1.1.0-1 - Update to upstream 1.1.0 release diff --git a/sources b/sources index a199c5b..18c183f 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (ultron-1.1.0.tgz) = a23dba415670d5df6e306ec516c5a1f99c7f7cffa0794d36fa9799017776050e0084b23043ea0b9e78f2760b31c3b2fea182a9300589618d02e338ffc9bf2ae4 +SHA512 (ultron-1.1.1.tgz) = 50811704d79898aa6d587eb3f199ea4de4bc7d5ef8cc6d3f79153d546929cf3f8b20936cf16ff333f2feedcb42911ae06cd9e7474c71c386ca3abd1c5b43743a diff --git a/test.js b/test.js index bb38826..b87fbf8 100644 --- a/test.js +++ b/test.js @@ -166,45 +166,6 @@ describe('Ultron', function () { assume(ee.listeners('foo')[0]).equals(foo); }); - it('removes our private __ultron references', function () { - function once() {} - function on() {} - - assume('__ultron' in once).is.false(); - assume('__ultron' in on).is.false(); - - ultron.on('foo', on); - ultron.once('bar', once); - - assume('__ultron' in once).is.true(); - assume('__ultron' in on).is.true(); - - ultron.remove('foo, bar'); - - assume('__ultron' in once).is.false(); - assume('__ultron' in on).is.false(); - - ee.removeAllListeners(); - ultron.destroy(); - - ee = new EE(); - ultron = new Ultron(ee); - - assume('__ultron' in once).is.false(); - assume('__ultron' in on).is.false(); - - ultron.on('foo', on); - ultron.once('bar', once); - - assume('__ultron' in once).is.true(); - assume('__ultron' in on).is.true(); - - ultron.remove('foo, bar'); - - assume('__ultron' in once).is.false(); - assume('__ultron' in on).is.false(); - }); - it('removes only our assigned `once` listeners', function () { function foo() {} function bar() {} @@ -229,7 +190,12 @@ describe('Ultron', function () { ultron.remove('foo'); assume(ee.listeners('foo').length).equals(1); - assume(ee.listeners('foo')[0].listener).equals(foo); + var actual = ee.listeners('foo')[0]; + // + // In Node.js 8+ `EventEmitter#listeners()` returns the original listener + // also for once listeners. + // + assume(actual.listener || actual).equals(foo); }); it('removes all assigned events if called without args', function () { @@ -240,14 +206,17 @@ describe('Ultron', function () { ultron.on('foo', foo); ultron.on('bar', bar); + ultron.on('baz', bar); assume(ee.listeners('foo').length).equals(1); assume(ee.listeners('bar').length).equals(1); + assume(ee.listeners('baz').length).equals(1); ultron.remove(); assume(ee.listeners('foo').length).equals(0); assume(ee.listeners('bar').length).equals(0); + assume(ee.listeners('baz').length).equals(0); ee.removeAllListeners(); ultron.destroy(); @@ -259,14 +228,17 @@ describe('Ultron', function () { ultron.on('foo', foo); ultron.on('bar', bar); + ultron.on('baz', bar); assume(ee.listeners('foo').length).equals(1); assume(ee.listeners('bar').length).equals(1); + assume(ee.listeners('baz').length).equals(1); ultron.remove(); assume(ee.listeners('foo').length).equals(0); assume(ee.listeners('bar').length).equals(0); + assume(ee.listeners('baz').length).equals(0); }); it('removes multiple listeners based on args', function () { @@ -289,7 +261,7 @@ describe('Ultron', function () { assume(ee.listeners('baz').length).equals(1); }); - it('removes multiple listeners if first arg is seperated string', function () { + it('removes multiple listeners if first arg is separated string', function () { function foo() {} function bar() {} function baz() {}