Intial Commit

This commit is contained in:
valki
2020-10-17 18:42:50 +02:00
commit 664c6d8ca3
5892 changed files with 759183 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
npm-debug.log
node_modules
.idea

View File

@@ -0,0 +1,95 @@
# tiny-emitter
A tiny (less than 1k) event emitter library. Works in the browser, in Node, and with [Browserify](http://browserify.org).
[![browser support](https://ci.testling.com/scottcorgan/tiny-emitter.png)](https://ci.testling.com/scottcorgan/tiny-emitter)
## Install
Node and Browserify
```
npm install tiny-emitter --save
```
Browser
```
bower install tiny-emitter --save
```
```html
<script src="bower_components/tiny-emitter/dist/tinyemitter.min.js"></script>
```
## Usage
Node and Browserify
```js
var Emitter = require('tiny-emitter');
var emitter = new Emitter();
emitter.on('some-event', function (arg1, arg2, arg3) {
//
});
emitter.emit('some-event', 'arg1 value', 'arg2 value', 'arg3 value');
```
Browser
```js
var emitter = new TinyEmitter();
emitter.on('some-event', someCallback);
emitter.emit('some-event');
```
## Instance Methods
### on(event, callback[, context])
Subscribe to an event
* `event` - the name of the event to subscribe to
* `callback` - the function to call when event is emitted
* `context` - (OPTIONAL) - the context to bind the event callback to
### once(event, callback[, context])
Subscribe to an event only **once**
* `event` - the name of the event to subscribe to
* `callback` - the function to call when event is emitted
* `context` - (OPTIONAL) - the context to bind the event callback to
### off(event[, callback])
Unsubscribe from an event or all events. If no callback is provided, it unsubscribes you from all events.
* `event` - the name of the event to unsubscribe from
* `callback` - the function used when binding to the event
### emit(event[, arguments...])
Trigger a named event
* `event` - the event name to emit
* `arguments...` - any number of arguments to pass to the event subscribers
## Test and Build
Build (Tests, Browserifies, and minifies)
```
npm install
npm run build
```
Test
```
npm install
npm test
```

View File

@@ -0,0 +1,29 @@
{
"name": "tiny-emitter",
"main": "dist/tinyemitter.js",
"version": "1.0.0",
"homepage": "https://github.com/scottcorgan/tiny-emitter",
"authors": [
"Scott Corgan <scottcorgan@gmail.com>"
],
"description": "A tiny (less than 1k) event emitter library",
"keywords": [
"emitter",
"tiny",
"event",
"pubsub",
"bind"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
".gitignore",
"index.js",
"package.json",
"bower.json"
]
}

View File

@@ -0,0 +1,70 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.TinyEmitter = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
function E () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
}
E.prototype = {
on: function (name, callback, ctx) {
var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({
fn: callback,
ctx: ctx
});
return this;
},
once: function (name, callback, ctx) {
var self = this;
function listener () {
self.off(name, listener);
callback.apply(ctx, arguments);
};
listener._ = callback
return this.on(name, listener, ctx);
},
emit: function (name) {
var data = [].slice.call(arguments, 1);
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0;
var len = evtArr.length;
for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data);
}
return this;
},
off: function (name, callback) {
var e = this.e || (this.e = {});
var evts = e[name];
var liveEvents = [];
if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
liveEvents.push(evts[i]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
(liveEvents.length)
? e[name] = liveEvents
: delete e[name];
return this;
}
};
module.exports = E;
},{}]},{},[1])(1)
});

View File

@@ -0,0 +1 @@
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var n;if(typeof window!=="undefined"){n=window}else if(typeof global!=="undefined"){n=global}else if(typeof self!=="undefined"){n=self}else{n=this}n.TinyEmitter=e()}})(function(){var e,n,t;return function r(e,n,t){function i(o,u){if(!n[o]){if(!e[o]){var s=typeof require=="function"&&require;if(!u&&s)return s(o,!0);if(f)return f(o,!0);var a=new Error("Cannot find module '"+o+"'");throw a.code="MODULE_NOT_FOUND",a}var l=n[o]={exports:{}};e[o][0].call(l.exports,function(n){var t=e[o][1][n];return i(t?t:n)},l,l.exports,r,e,n,t)}return n[o].exports}var f=typeof require=="function"&&require;for(var o=0;o<t.length;o++)i(t[o]);return i}({1:[function(e,n,t){function r(){}r.prototype={on:function(e,n,t){var r=this.e||(this.e={});(r[e]||(r[e]=[])).push({fn:n,ctx:t});return this},once:function(e,n,t){var r=this;function i(){r.off(e,i);n.apply(t,arguments)}i._=n;return this.on(e,i,t)},emit:function(e){var n=[].slice.call(arguments,1);var t=((this.e||(this.e={}))[e]||[]).slice();var r=0;var i=t.length;for(r;r<i;r++){t[r].fn.apply(t[r].ctx,n)}return this},off:function(e,n){var t=this.e||(this.e={});var r=t[e];var i=[];if(r&&n){for(var f=0,o=r.length;f<o;f++){if(r[f].fn!==n&&r[f].fn._!==n)i.push(r[f])}}i.length?t[e]=i:delete t[e];return this}};n.exports=r},{}]},{},[1])(1)});

View File

@@ -0,0 +1,7 @@
declare class EventEmitter {
on (event: string, callback: Function, ctx?: any): EventEmitter;
once (event: string, callback: Function, ctx?: any): EventEmitter;
emit (event: string, ...args: any[]): EventEmitter;
off (event: string, callback?: Function): EventEmitter;
}
export = EventEmitter

66
nodered/rootfs/data/node_modules/tiny-emitter/index.js generated vendored Normal file
View File

@@ -0,0 +1,66 @@
function E () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
}
E.prototype = {
on: function (name, callback, ctx) {
var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({
fn: callback,
ctx: ctx
});
return this;
},
once: function (name, callback, ctx) {
var self = this;
function listener () {
self.off(name, listener);
callback.apply(ctx, arguments);
};
listener._ = callback
return this.on(name, listener, ctx);
},
emit: function (name) {
var data = [].slice.call(arguments, 1);
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0;
var len = evtArr.length;
for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data);
}
return this;
},
off: function (name, callback) {
var e = this.e || (this.e = {});
var evts = e[name];
var liveEvents = [];
if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
liveEvents.push(evts[i]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
(liveEvents.length)
? e[name] = liveEvents
: delete e[name];
return this;
}
};
module.exports = E;

View File

@@ -0,0 +1,80 @@
{
"_from": "tiny-emitter@1.1.0",
"_id": "tiny-emitter@1.1.0",
"_inBundle": false,
"_integrity": "sha1-q0BaIf/tgUp2wZc5ZICT1wZU/ss=",
"_location": "/tiny-emitter",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "tiny-emitter@1.1.0",
"name": "tiny-emitter",
"escapedName": "tiny-emitter",
"rawSpec": "1.1.0",
"saveSpec": null,
"fetchSpec": "1.1.0"
},
"_requiredBy": [
"/mathjs"
],
"_resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-1.1.0.tgz",
"_shasum": "ab405a21ffed814a76c19739648093d70654fecb",
"_spec": "tiny-emitter@1.1.0",
"_where": "/data/node_modules/mathjs",
"author": {
"name": "Scott Corgan"
},
"bugs": {
"url": "https://github.com/scottcorgan/tiny-emitter/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "A tiny (less than 1k) event emitter library",
"devDependencies": {
"@tap-format/spec": "0.2.0",
"browserify": "^11.2.0",
"tape": "^4.2.1",
"testling": "^1.7.1",
"uglify-js": "^2.5.0"
},
"homepage": "https://github.com/scottcorgan/tiny-emitter#readme",
"keywords": [
"event",
"emitter",
"pubsub",
"tiny",
"events",
"bind"
],
"license": "MIT",
"main": "index.js",
"name": "tiny-emitter",
"repository": {
"type": "git",
"url": "git+https://github.com/scottcorgan/tiny-emitter.git"
},
"scripts": {
"build": "npm test && npm run bundle && npm run minify",
"bundle": "browserify index.js > dist/tinyemitter.js -s TinyEmitter && echo 'Bundled'",
"minify": "uglifyjs dist/tinyemitter.js -o dist/tinyemitter.min.js -m && echo 'Minified'",
"size": "uglifyjs index.js -o minified.js -m && ls -l && rm minified.js",
"test": "testling | tap-format-spec"
},
"testling": {
"files": [
"test/index.js"
],
"browsers": [
"iexplore/10.0",
"iexplore/9.0",
"firefox/16..latest",
"chrome/22..latest",
"safari/5.1..latest",
"ipad/6.0..latest",
"iphone/6.0..latest",
"android-browser/4.2..latest"
]
},
"version": "1.1.0"
}

View File

@@ -0,0 +1,210 @@
var Emitter = require('../index.js');
var test = require('tape');
test('subscribes to an event', function (t) {
var emitter = new Emitter();
emitter.on('test', function () {});
t.equal(emitter.e.test.length, 1, 'subscribed to event');
t.end();
});
test('subscribes to an event with context', function (t) {
var emitter = new Emitter();
var context = {
contextValue: true
};
emitter.on('test', function () {
t.ok(this.contextValue, 'is in context');
t.end();
}, context);
emitter.emit('test');
});
test('subscibes only once to an event', function (t) {
var emitter = new Emitter();
emitter.once('test', function () {
t.notOk(emitter.e.test, 'removed event from list');
t.end();
});
emitter.emit('test');
});
test('keeps context when subscribed only once', function (t) {
var emitter = new Emitter();
var context = {
contextValue: true
};
emitter.once('test', function () {
t.ok(this.contextValue, 'is in context');
t.notOk(emitter.e.test, 'not subscribed anymore');
t.end();
}, context);
emitter.emit('test');
});
test('emits an event', function (t) {
var emitter = new Emitter();
emitter.on('test', function () {
t.ok(true, 'triggered event');
t.end();
});
emitter.emit('test');
});
test('passes all arguments to event listener', function (t) {
var emitter = new Emitter();
emitter.on('test', function (arg1, arg2) {
t.equal(arg1, 'arg1', 'passed the first argument');
t.equal(arg2, 'arg2', 'passed the second argument');
t.end();
});
emitter.emit('test', 'arg1', 'arg2');
});
test('unsubscribes from all events with name', function (t) {
var emitter = new Emitter();
emitter.on('test', function () {
t.ok(false, 'should not get called');
});
emitter.off('test');
emitter.emit('test')
process.nextTick(function () {
t.end();
});
});
test('unsubscribes single event with name and callback', function (t) {
var emitter = new Emitter();
var fn = function () {
t.ok(false, 'should not get called');
}
emitter.on('test', fn);
emitter.off('test', fn);
emitter.emit('test')
process.nextTick(function () {
t.end();
});
});
// Test added by https://github.com/lazd
// From PR: https://github.com/scottcorgan/tiny-emitter/pull/6
test('unsubscribes single event with name and callback when subscribed twice', function (t) {
var emitter = new Emitter();
var fn = function () {
t.ok(false, 'should not get called');
};
emitter.on('test', fn);
emitter.on('test', fn);
emitter.off('test', fn);
emitter.emit('test');
process.nextTick(function () {
t.notOk(emitter.e['test'], 'removes all events');
t.end();
});
});
test('unsubscribes single event with name and callback when subscribed twice out of order', function (t) {
var emitter = new Emitter();
var calls = 0;
var fn = function () {
t.ok(false, 'should not get called');
};
var fn2 = function () {
calls++;
};
emitter.on('test', fn);
emitter.on('test', fn2);
emitter.on('test', fn);
emitter.off('test', fn);
emitter.emit('test');
process.nextTick(function () {
t.equal(calls, 1, 'callback was called');
t.end();
});
});
test('removes an event inside another event', function (t) {
var emitter = new Emitter();
emitter.on('test', function () {
t.equal(emitter.e.test.length, 1, 'event is still in list');
emitter.off('test');
t.notOk(emitter.e.test, 0, 'event is gone from list');
t.end();
});
emitter.emit('test');
});
test('event is emitted even if unsubscribed in the event callback', function (t) {
var emitter = new Emitter();
var calls = 0;
var fn = function () {
calls += 1;
emitter.off('test', fn);
};
emitter.on('test', fn);
emitter.on('test', function () {
calls += 1;
});
emitter.on('test', function () {
calls += 1;
});
process.nextTick(function () {
t.equal(calls, 3, 'all callbacks were called');
t.end();
});
emitter.emit('test');
});
test('calling off before any events added does nothing', function (t) {
var emitter = new Emitter();
emitter.off('test', function () {});
t.end();
});
test('emitting event that has not been subscribed to yet', function (t) {
var emitter = new Emitter();
emitter.emit('some-event', 'some message');
t.end();
});
test('unsubscribes single event with name and callback which was subscribed once', function (t) {
var emitter = new Emitter();
var fn = function () {
t.fail('event not unsubscribed');
}
emitter.once('test', fn);
emitter.off('test', fn);
emitter.emit('test');
t.end();
});