-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.json
62 lines (62 loc) · 8.7 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{
"name": "eventemitter2",
"version": "0.4.14",
"description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.",
"keywords": [
"event",
"events",
"emitter",
"eventemitter"
],
"author": {
"name": "hij1nx",
"email": "paolo@async.ly"
},
"contributors": [
{
"name": "Eric Elliott"
},
{
"name": "Charlie Robbins",
"email": "charlie@nodejitsu.com"
},
{
"name": "Jameson Lee",
"email": "jameson@nodejitsu.com"
},
{
"name": "Jeroen van Duffelen",
"email": "jvduf@nodejitsu.com"
},
{
"name": "Fedor Indutny",
"email": "fedor.indutny@gmail.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/hij1nx/EventEmitter2.git"
},
"devDependencies": {
"nodeunit": "*",
"benchmark": ">= 0.2.2"
},
"main": "./lib/eventemitter2.js",
"scripts": {
"test": "nodeunit test/simple/ && nodeunit test/wildcardEvents/",
"benchmark": "node test/perf/benchmark.js"
},
"files": [
"lib/eventemitter2.js",
"index.js"
],
"readme": "[![build-status](https://www.codeship.io/projects/3ad58940-4c7d-0131-15d5-5a8cd3f550f8/status)](https://www.codeship.io/projects/11259)\n\n# SYNOPSIS\n\nEventEmitter2 is an implementation of the EventEmitter found in Node.js\n\n# DESCRIPTION\n\n### FEATURES\n - Namespaces/Wildcards.\n - Times To Listen (TTL), extends the `once` concept with `many`.\n - Browser environment compatibility.\n - Demonstrates good performance in benchmarks\n\n```\nEventEmitterHeatUp x 3,728,965 ops/sec \\302\\2610.68% (60 runs sampled)\nEventEmitter x 2,822,904 ops/sec \\302\\2610.74% (63 runs sampled)\nEventEmitter2 x 7,251,227 ops/sec \\302\\2610.55% (58 runs sampled)\nEventEmitter2 (wild) x 3,220,268 ops/sec \\302\\2610.44% (65 runs sampled)\nFastest is EventEmitter2\n```\n\n### Differences (Non breaking, compatible with existing EventEmitter)\n\n - The constructor takes a configuration object.\n \n```javascript\n var EventEmitter2 = require('eventemitter2').EventEmitter2;\n var server = new EventEmitter2({\n\n //\n // use wildcards.\n //\n wildcard: true,\n\n //\n // the delimiter used to segment namespaces, defaults to `.`.\n //\n delimiter: '::', \n \n //\n // if you want to emit the newListener event set to true.\n //\n newListener: false, \n\n //\n // max listeners that can be assigned to an event, default 10.\n //\n maxListeners: 20\n });\n```\n\n - Getting the actual event that fired.\n\n```javascript\n server.on('foo.*', function(value1, value2) {\n console.log(this.event, value1, value2);\n });\n```\n\n - Fire an event N times and then remove it, an extension of the `once` concept.\n\n```javascript\n server.many('foo', 4, function() {\n console.log('hello');\n });\n```\n\n - Pass in a namespaced event as an array rather than a delimited string.\n\n```javascript\n server.many(['foo', 'bar', 'bazz'], function() {\n console.log('hello');\n });\n```\n\n\n# API\n\nWhen an `EventEmitter` instance experiences an error, the typical action is\nto emit an `error` event. Error events are treated as a special case.\nIf there is no listener for it, then the default action is to print a stack\ntrace and exit the program.\n\nAll EventEmitters emit the event `newListener` when new listeners are\nadded.\n\n\n**Namespaces** with **Wildcards**\nTo use namespaces/wildcards, pass the `wildcard` option into the EventEmitter \nconstructor. When namespaces/wildcards are enabled, events can either be \nstrings (`foo.bar`) separated by a delimiter or arrays (`['foo', 'bar']`). The \ndelimiter is also configurable as a constructor option.\n\nAn event name passed to any event emitter method can contain a wild card (the \n`*` character). If the event name is a string, a wildcard may appear as `foo.*`. \nIf the event name is an array, the wildcard may appear as `['foo', '*']`.\n\nIf either of the above described events were passed to the `on` method, \nsubsequent emits such as the following would be observed...\n\n```javascript\n emitter.emit('foo.bazz');\n emitter.emit(['foo', 'bar']);\n```\n\n\n### emitter.addListener(event, listener)\n### emitter.on(event, listener)\n\nAdds a listener to the end of the listeners array for the specified event.\n\n```javascript\n server.on('data', function(value1, value2, value3, ...) {\n console.log('The event was raised!');\n });\n```\n\n```javascript\n server.on('data', function(value) {\n console.log('The event was raised!');\n });\n```\n\n### emitter.onAny(listener)\n\nAdds a listener that will be fired when any event is emitted.\n\n```javascript\n server.onAny(function(value) {\n console.log('All events trigger this.');\n });\n```\n\n### emitter.offAny(listener)\n\nRemoves the listener that will be fired when any event is emitted.\n\n```javascript\n server.offAny(function(value) {\n console.log('The event was raised!');\n });\n```\n\n#### emitter.once(event, listener)\n\nAdds a **one time** listener for the event. The listener is invoked \nonly the first time the event is fired, after which it is removed.\n\n```javascript\n server.once('get', function (value) {\n console.log('Ah, we have our first value!');\n });\n```\n\n### emitter.many(event, timesToListen, listener)\n\nAdds a listener that will execute **n times** for the event before being\nremoved. The listener is invoked only the first **n times** the event is \nfired, after which it is removed.\n\n```javascript\n server.many('get', 4, function (value) {\n console.log('This event will be listened to exactly four times.');\n });\n```\n\n\n### emitter.removeListener(event, listener)\n### emitter.off(event, listener)\n\nRemove a listener from the listener array for the specified event. \n**Caution**: changes array indices in the listener array behind the listener.\n\n```javascript\n var callback = function(value) {\n console.log('someone connected!');\n };\n server.on('get', callback);\n // ...\n server.removeListener('get', callback);\n```\n\n\n### emitter.removeAllListeners([event])\n\nRemoves all listeners, or those of the specified event.\n\n\n### emitter.setMaxListeners(n)\n\nBy default EventEmitters will print a warning if more than 10 listeners \nare added to it. This is a useful default which helps finding memory leaks. \nObviously not all Emitters should be limited to 10. This function allows \nthat to be increased. Set to zero for unlimited.\n\n\n### emitter.listeners(event)\n\nReturns an array of listeners for the specified event. This array can be \nmanipulated, e.g. to remove listeners.\n\n```javascript\n server.on('get', function(value) {\n console.log('someone connected!');\n });\n console.log(server.listeners('get')); // [ [Function] ]\n```\n\n### emitter.listenersAny()\n\nReturns an array of listeners that are listening for any event that is \nspecified. This array can be manipulated, e.g. to remove listeners.\n\n```javascript\n server.onAny(function(value) {\n console.log('someone connected!');\n });\n console.log(server.listenersAny()[0]); // [ [Function] ]\n```\n\n### emitter.emit(event, [arg1], [arg2], [...])\n\nExecute each of the listeners that may be listening for the specified event \nname in order with the list of arguments.\n\n# LICENSE\n\n(The MIT License)\n\nCopyright (c) 2011 hij1nx <http://www.twitter.com/hij1nx>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy \nof this software and associated documentation files (the 'Software'), to deal \nin the Software without restriction, including without limitation the rights \nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell \ncopies of the Software, and to permit persons to whom the Software is furnished\nto do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR \nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR \nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\nAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION \nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/hij1nx/EventEmitter2/issues"
},
"homepage": "https://github.com/hij1nx/EventEmitter2",
"_id": "eventemitter2@0.4.14",
"_from": "eventemitter2@~0.4.13"
}