mqtt stuff added
This commit is contained in:
22
node_modules/ultron/LICENSE
generated
vendored
Normal file
22
node_modules/ultron/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Unshift.io, Arnout Kazemier, the Contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
113
node_modules/ultron/README.md
generated
vendored
Normal file
113
node_modules/ultron/README.md
generated
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
# Ultron
|
||||
|
||||
[](http://unshift.io)[](http://browsenpm.org/package/ultron)[](https://travis-ci.org/unshiftio/ultron)[](https://david-dm.org/unshiftio/ultron)[](https://coveralls.io/r/unshiftio/ultron?branch=master)[](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
|
136
node_modules/ultron/index.js
generated
vendored
Normal file
136
node_modules/ultron/index.js
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
/**
|
||||
* An auto incrementing id which we can use to create "unique" Ultron instances
|
||||
* so we can track the event emitters that are added through the Ultron
|
||||
* interface.
|
||||
*
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
var id = 0;
|
||||
|
||||
/**
|
||||
* Ultron is high-intelligence robot. It gathers intelligence so it can start improving
|
||||
* upon his rudimentary design. It will learn from your EventEmitting patterns
|
||||
* and exterminate them.
|
||||
*
|
||||
* @constructor
|
||||
* @param {EventEmitter} ee EventEmitter instance we need to wrap.
|
||||
* @api public
|
||||
*/
|
||||
function Ultron(ee) {
|
||||
if (!(this instanceof Ultron)) return new Ultron(ee);
|
||||
|
||||
this.id = id++;
|
||||
this.ee = ee;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new EventListener for the given event.
|
||||
*
|
||||
* @param {String} event Name of the event.
|
||||
* @param {Functon} fn Callback function.
|
||||
* @param {Mixed} context The context of the function.
|
||||
* @returns {Ultron}
|
||||
* @api public
|
||||
*/
|
||||
Ultron.prototype.on = function on(event, fn, context) {
|
||||
fn.__ultron = this.id;
|
||||
this.ee.on(event, fn, context);
|
||||
|
||||
return this;
|
||||
};
|
||||
/**
|
||||
* Add an EventListener that's only called once.
|
||||
*
|
||||
* @param {String} event Name of the event.
|
||||
* @param {Function} fn Callback function.
|
||||
* @param {Mixed} context The context of the function.
|
||||
* @returns {Ultron}
|
||||
* @api public
|
||||
*/
|
||||
Ultron.prototype.once = function once(event, fn, context) {
|
||||
fn.__ultron = this.id;
|
||||
this.ee.once(event, fn, context);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove the listeners we assigned for the given event.
|
||||
*
|
||||
* @returns {Ultron}
|
||||
* @api public
|
||||
*/
|
||||
Ultron.prototype.remove = function remove() {
|
||||
var args = arguments
|
||||
, ee = this.ee
|
||||
, event;
|
||||
|
||||
//
|
||||
// When no event names are provided we assume that we need to clear all the
|
||||
// events that were assigned through us.
|
||||
//
|
||||
if (args.length === 1 && 'string' === typeof args[0]) {
|
||||
args = args[0].split(/[, ]+/);
|
||||
} else if (!args.length) {
|
||||
if (ee.eventNames) {
|
||||
args = ee.eventNames();
|
||||
} else if (ee._events) {
|
||||
args = [];
|
||||
|
||||
for (event in ee._events) {
|
||||
if (has.call(ee._events, event)) args.push(event);
|
||||
}
|
||||
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
args = args.concat(Object.getOwnPropertySymbols(ee._events));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var listeners = ee.listeners(args[i]);
|
||||
|
||||
for (var j = 0; j < listeners.length; j++) {
|
||||
event = listeners[j];
|
||||
|
||||
//
|
||||
// Once listeners have a `listener` property that stores the real listener
|
||||
// in the EventEmitter that ships with Node.js.
|
||||
//
|
||||
if (event.listener) {
|
||||
if (event.listener.__ultron !== this.id) continue;
|
||||
} else if (event.__ultron !== this.id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ee.removeListener(args[i], event);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroy the Ultron instance, remove all listeners and release all references.
|
||||
*
|
||||
* @returns {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
Ultron.prototype.destroy = function destroy() {
|
||||
if (!this.ee) return false;
|
||||
|
||||
this.remove();
|
||||
this.ee = null;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
//
|
||||
// Expose the module.
|
||||
//
|
||||
module.exports = Ultron;
|
68
node_modules/ultron/package.json
generated
vendored
Normal file
68
node_modules/ultron/package.json
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
{
|
||||
"_from": "ultron@~1.1.0",
|
||||
"_id": "ultron@1.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==",
|
||||
"_location": "/ultron",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "ultron@~1.1.0",
|
||||
"name": "ultron",
|
||||
"escapedName": "ultron",
|
||||
"rawSpec": "~1.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "~1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ws"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
|
||||
"_shasum": "9fe1536a10a664a65266a1e3ccf85fd36302bc9c",
|
||||
"_spec": "ultron@~1.1.0",
|
||||
"_where": "/home/wn/workspace-node/PiAlive/node_modules/ws",
|
||||
"author": {
|
||||
"name": "Arnout Kazemier"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/unshiftio/ultron/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Ultron is high-intelligence robot. It gathers intel so it can start improving upon his rudimentary design",
|
||||
"devDependencies": {
|
||||
"assume": "~1.5.0",
|
||||
"eventemitter3": "2.0.x",
|
||||
"istanbul": "0.4.x",
|
||||
"mocha": "~4.0.0",
|
||||
"pre-commit": "~1.2.0"
|
||||
},
|
||||
"homepage": "https://github.com/unshiftio/ultron",
|
||||
"keywords": [
|
||||
"Ultron",
|
||||
"robot",
|
||||
"gather",
|
||||
"intelligence",
|
||||
"event",
|
||||
"events",
|
||||
"eventemitter",
|
||||
"emitter",
|
||||
"cleanup"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "ultron",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/unshiftio/ultron.git"
|
||||
},
|
||||
"scripts": {
|
||||
"100%": "istanbul check-coverage --statements 100 --functions 100 --lines 100 --branches 100",
|
||||
"coverage": "istanbul cover _mocha -- test.js",
|
||||
"test": "mocha test.js",
|
||||
"test-travis": "istanbul cover _mocha --report lcovonly -- test.js",
|
||||
"watch": "mocha --watch test.js"
|
||||
},
|
||||
"version": "1.1.1"
|
||||
}
|
Reference in New Issue
Block a user