08-27-周三_17-09-29
This commit is contained in:
22
node_modules/tiny-emitter/LICENSE
generated
vendored
Normal file
22
node_modules/tiny-emitter/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Scott Corgan
|
||||
|
||||
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.
|
||||
|
88
node_modules/tiny-emitter/README.md
generated
vendored
Normal file
88
node_modules/tiny-emitter/README.md
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
# tiny-emitter
|
||||
|
||||
A tiny (less than 1k) event emitter library.
|
||||
|
||||
## Install
|
||||
|
||||
### npm
|
||||
|
||||
```
|
||||
npm install tiny-emitter --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```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');
|
||||
```
|
||||
|
||||
Alternatively, you can skip the initialization step by requiring `tiny-emitter/instance` instead. This pulls in an already initialized emitter.
|
||||
|
||||
```js
|
||||
var emitter = require('tiny-emitter/instance');
|
||||
|
||||
emitter.on('some-event', function (arg1, arg2, arg3) {
|
||||
//
|
||||
});
|
||||
|
||||
emitter.emit('some-event', 'arg1 value', 'arg2 value', 'arg3 value');
|
||||
```
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/scottcorgan/tiny-emitter/blob/master/LICENSE)
|
71
node_modules/tiny-emitter/dist/tinyemitter.js
generated
vendored
Normal file
71
node_modules/tiny-emitter/dist/tinyemitter.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
(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;
|
||||
module.exports.TinyEmitter = E;
|
||||
|
||||
},{}]},{},[1])(1)
|
||||
});
|
1
node_modules/tiny-emitter/dist/tinyemitter.min.js
generated
vendored
Normal file
1
node_modules/tiny-emitter/dist/tinyemitter.min.js
generated
vendored
Normal 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;n.exports.TinyEmitter=r},{}]},{},[1])(1)});
|
6
node_modules/tiny-emitter/index.d.ts
generated
vendored
Normal file
6
node_modules/tiny-emitter/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export declare class TinyEmitter {
|
||||
on(event: string, callback: Function, ctx?: any): this;
|
||||
once(event: string, callback: Function, ctx?: any): this;
|
||||
emit(event: string, ...args: any[]): this;
|
||||
off(event: string, callback?: Function): this;
|
||||
}
|
67
node_modules/tiny-emitter/index.js
generated
vendored
Normal file
67
node_modules/tiny-emitter/index.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
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;
|
||||
module.exports.TinyEmitter = E;
|
2
node_modules/tiny-emitter/instance.js
generated
vendored
Normal file
2
node_modules/tiny-emitter/instance.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var E = require('./index.js');
|
||||
module.exports = new E();
|
121
node_modules/tiny-emitter/package.json
generated
vendored
Normal file
121
node_modules/tiny-emitter/package.json
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "tiny-emitter",
|
||||
"raw": "tiny-emitter@^2.0.0",
|
||||
"rawSpec": "^2.0.0",
|
||||
"scope": null,
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\clipboard"
|
||||
]
|
||||
],
|
||||
"_from": "tiny-emitter@>=2.0.0 <3.0.0",
|
||||
"_hasShrinkwrap": false,
|
||||
"_id": "tiny-emitter@2.1.0",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/tiny-emitter",
|
||||
"_nodeVersion": "8.12.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/tiny-emitter_2.1.0_1549381252634_0.40391833556455703"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "scottcorgan@gmail.com",
|
||||
"name": "scottcorgan"
|
||||
},
|
||||
"_npmVersion": "6.4.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "tiny-emitter",
|
||||
"raw": "tiny-emitter@^2.0.0",
|
||||
"rawSpec": "^2.0.0",
|
||||
"scope": null,
|
||||
"spec": ">=2.0.0 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/clipboard"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz",
|
||||
"_shasum": "1d1a56edfc51c43e863cbb5382a72330e3555423",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "tiny-emitter@^2.0.0",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\clipboard",
|
||||
"author": {
|
||||
"name": "Scott Corgan"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/scottcorgan/tiny-emitter/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"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"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"fileCount": 10,
|
||||
"integrity": "sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==",
|
||||
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcWa6FCRA9TVsSAnZWagAAg5UP/1hFRSNs+J7T0dZ+okZl\nRqw0p0QT8MCOHTkPS6FaLevkPMcXKMuG+ZIlshfHmfKN0ablFgCMrIq4LrJa\nocZhOS5iBqHA9v5+qh74xnxyLrUgZN3INS0LJ5lMsSR+/04ivjNpcQgWZMn1\n7v4SpjCFAQtZH36zFQvrJzN40j+XsUvIItrYYe614gnmVOrtlh5r27VmlgQM\ndPhNgY6JIXCB8tg5jGn0VR63vJ5Q1TeNAdrswnnjueGLcrqDWOhVE6EVQauC\nM31R6oXA7miA4qIWSBAOXV7l7ZaC/DKCcJEgCuQOkQMq2aNH8JVHwePMAIP6\nwNipSC/NoiT0zTk2fX22e3knodJHH5JWJZIsRU0UZSChQ63nGtr+rgGhXAzd\nKitF2v0QFj6fHDhbuOsHQ5Lj7/6s9AKQKYyqPUDooVpFObXpqA0Ctcw1D7BA\nVc5tHJ3j/HLsg2ZdlaSUd2y0p5rez/4YTkDaA38SRMJcw9JltP2fVAypo6ck\n3xHu81lxQtE9FO61ZzgIACN5rPBmiVI6T26up0aWCLeicTzR/G21fsD1TJN9\nl7OPohk1z3DEaXTudpU09ZzUPcXZL2Ay9DG7Qy5u2mBL0gWJC8VMDmVgj9B9\nXef69mwVL1Ogz8ykkSpPJIl9wQ2O+Ww408/4lS7amCNqqVAhsv5OpbmLb+cF\nRCSK\r\n=SsCo\r\n-----END PGP SIGNATURE-----\r\n",
|
||||
"shasum": "1d1a56edfc51c43e863cbb5382a72330e3555423",
|
||||
"tarball": "https://registry.npmjs.org/tiny-emitter/-/tiny-emitter-2.1.0.tgz",
|
||||
"unpackedSize": 77178
|
||||
},
|
||||
"gitHead": "a6026cc94da5d2d164104dd30586eee6bb4fb29c",
|
||||
"homepage": "https://github.com/scottcorgan/tiny-emitter#readme",
|
||||
"keywords": [
|
||||
"event",
|
||||
"emitter",
|
||||
"pubsub",
|
||||
"tiny",
|
||||
"events",
|
||||
"bind"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "scottcorgan@gmail.com",
|
||||
"name": "scottcorgan"
|
||||
}
|
||||
],
|
||||
"name": "tiny-emitter",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"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",
|
||||
"test-node": "tape test/index.js | tap-format-spec"
|
||||
},
|
||||
"testling": {
|
||||
"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"
|
||||
],
|
||||
"files": [
|
||||
"test/index.js"
|
||||
]
|
||||
},
|
||||
"version": "2.1.0"
|
||||
}
|
217
node_modules/tiny-emitter/test/index.js
generated
vendored
Normal file
217
node_modules/tiny-emitter/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
var Emitter = require('../index');
|
||||
var emitter = require('../instance');
|
||||
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.fail('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.fail('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.fail('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.fail('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();
|
||||
});
|
||||
|
||||
test('exports an instance', function (t) {
|
||||
t.ok(emitter, 'exports an instance')
|
||||
t.ok(emitter instanceof Emitter, 'an instance of the Emitter class');
|
||||
t.end();
|
||||
});
|
1857
node_modules/tiny-emitter/yarn.lock
generated
vendored
Normal file
1857
node_modules/tiny-emitter/yarn.lock
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user