From 26105034da4fcce7ac883c899d781f016559310d Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 8 Nov 2018 00:38:48 +0800 Subject: switch to vuepress --- node_modules/tiny-emitter/.npmignore | 14 ++ node_modules/tiny-emitter/LICENSE | 22 +++ node_modules/tiny-emitter/README.md | 88 +++++++++ node_modules/tiny-emitter/dist/tinyemitter.js | 70 +++++++ node_modules/tiny-emitter/dist/tinyemitter.min.js | 1 + node_modules/tiny-emitter/index.d.ts | 8 + node_modules/tiny-emitter/index.js | 66 +++++++ node_modules/tiny-emitter/instance.js | 2 + node_modules/tiny-emitter/package.json | 53 ++++++ node_modules/tiny-emitter/test/index.js | 217 ++++++++++++++++++++++ 10 files changed, 541 insertions(+) create mode 100644 node_modules/tiny-emitter/.npmignore create mode 100644 node_modules/tiny-emitter/LICENSE create mode 100644 node_modules/tiny-emitter/README.md create mode 100644 node_modules/tiny-emitter/dist/tinyemitter.js create mode 100644 node_modules/tiny-emitter/dist/tinyemitter.min.js create mode 100644 node_modules/tiny-emitter/index.d.ts create mode 100644 node_modules/tiny-emitter/index.js create mode 100644 node_modules/tiny-emitter/instance.js create mode 100644 node_modules/tiny-emitter/package.json create mode 100644 node_modules/tiny-emitter/test/index.js (limited to 'node_modules/tiny-emitter') diff --git a/node_modules/tiny-emitter/.npmignore b/node_modules/tiny-emitter/.npmignore new file mode 100644 index 00000000..6580b973 --- /dev/null +++ b/node_modules/tiny-emitter/.npmignore @@ -0,0 +1,14 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz +pids +logs +results +npm-debug.log +node_modules +.idea \ No newline at end of file diff --git a/node_modules/tiny-emitter/LICENSE b/node_modules/tiny-emitter/LICENSE new file mode 100644 index 00000000..24f10246 --- /dev/null +++ b/node_modules/tiny-emitter/LICENSE @@ -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. + diff --git a/node_modules/tiny-emitter/README.md b/node_modules/tiny-emitter/README.md new file mode 100644 index 00000000..cd474cd0 --- /dev/null +++ b/node_modules/tiny-emitter/README.md @@ -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) diff --git a/node_modules/tiny-emitter/dist/tinyemitter.js b/node_modules/tiny-emitter/dist/tinyemitter.js new file mode 100644 index 00000000..956acb2e --- /dev/null +++ b/node_modules/tiny-emitter/dist/tinyemitter.js @@ -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 dist/tinyemitter.js -s TinyEmitter && echo 'Bundled'", + "minify": "node_modules/.bin/uglifyjs dist/tinyemitter.js -o dist/tinyemitter.min.js -m && echo 'Minified'", + "build": "npm test && npm run bundle && npm run minify", + "size": "node_modules/.bin/uglifyjs index.js -o minified.js -m && ls -l && rm minified.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/scottcorgan/tiny-emitter.git" + }, + "keywords": [ + "event", + "emitter", + "pubsub", + "tiny", + "events", + "bind" + ], + "author": "Scott Corgan", + "license": "MIT", + "bugs": { + "url": "https://github.com/scottcorgan/tiny-emitter/issues" + }, + "devDependencies": { + "@tap-format/spec": "0.2.0", + "browserify": "11.2.0", + "tape": "4.2.1", + "testling": "1.7.1", + "uglify-js": "2.5.0" + }, + "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" + ] + } +} diff --git a/node_modules/tiny-emitter/test/index.js b/node_modules/tiny-emitter/test/index.js new file mode 100644 index 00000000..7f95f62f --- /dev/null +++ b/node_modules/tiny-emitter/test/index.js @@ -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(); +}); -- cgit v1.2.3