{"_id":"events-listener","_rev":"6-ecaa4709996ff0ece0d6d9406ea8cd62","name":"events-listener","description":"Listen to events from a Node.js EventEmitter.","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"events-listener","version":"1.0.0","description":"Listen to events from a Node.js EventEmitter.","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/jwalton/node-events-listener.git"},"keywords":["events","node"],"author":{"name":"Jason Walton"},"license":"MIT","bugs":{"url":"https://github.com/jwalton/node-events-listener/issues"},"homepage":"https://github.com/jwalton/node-events-listener#readme","devDependencies":{"mocha":"^3.3.0","sinon":"^2.1.0"},"gitHead":"6ab7dfa3d32d97c7bebaa31d801b0bfeddbf6be6","_id":"events-listener@1.0.0","_shasum":"4b7bc8fce87e105ac4b6d3f42c667f1fe02ee1c5","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.10.0","_npmUser":{"name":"jwalton","email":"npm@lucid.thedreaming.org"},"dist":{"shasum":"4b7bc8fce87e105ac4b6d3f42c667f1fe02ee1c5","tarball":"https://registry.npmjs.org/events-listener/-/events-listener-1.0.0.tgz","integrity":"sha512-YmCdVhE5Z3aOXceVnVqMuHz8FYGMUk1sA36bJ7jK33dVP3fPaxbAtxxQ7TfYZbUp2hGWS/c4cYW2R1kuA5mDCg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDT0qvs22onaph1mxnAv0fInwCbfAwH87LqTwtPR9fw1QIgM9/XWwdVwIWgX+ocn2OdLJKdRIq/tUj76iGomNSrb2o="}]},"maintainers":[{"name":"jwalton","email":"npm@lucid.thedreaming.org"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/events-listener-1.0.0.tgz_1493580331331_0.5961449118331075"},"directories":{}},"1.0.1":{"name":"events-listener","version":"1.0.1","description":"Listen to events from a Node.js EventEmitter.","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/jwalton/node-events-listener.git"},"keywords":["events","EventEmitter","listenTo","node","node.js","stopListening"],"author":{"name":"Jason Walton"},"license":"MIT","bugs":{"url":"https://github.com/jwalton/node-events-listener/issues"},"homepage":"https://github.com/jwalton/node-events-listener#readme","devDependencies":{"mocha":"^3.3.0","sinon":"^2.1.0"},"gitHead":"50330b4e68d5cc73effb72f2ce2518e44c3489f5","_id":"events-listener@1.0.1","_shasum":"6df94232a9801c324d4fb2105d2129085d894385","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.10.0","_npmUser":{"name":"jwalton","email":"npm@lucid.thedreaming.org"},"dist":{"shasum":"6df94232a9801c324d4fb2105d2129085d894385","tarball":"https://registry.npmjs.org/events-listener/-/events-listener-1.0.1.tgz","integrity":"sha512-MnHJDhEu2jZYt2brqKJrbR8fFUlTOLowd4NptNSmOmnfNK6/zFRbkFal0LV3nR36kYGSJpmrxWfN4zIJF8okwA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCSzikRSHVY3aTb+BuBDfhbuoy9CpBYu8woijkicGjvOgIgBVzD4q/t/bq5bQPVn839Qs5Fj1LMP7A5EJV+zqgEazg="}]},"maintainers":[{"name":"jwalton","email":"npm@lucid.thedreaming.org"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/events-listener-1.0.1.tgz_1493586031266_0.7677596739958972"},"directories":{}},"1.0.2":{"name":"events-listener","version":"1.0.2","description":"Listen to events from a Node.js EventEmitter.","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/jwalton/node-events-listener.git"},"keywords":["events","EventEmitter","listenTo","node","node.js","stopListening"],"author":{"name":"Jason Walton"},"license":"MIT","bugs":{"url":"https://github.com/jwalton/node-events-listener/issues"},"homepage":"https://github.com/jwalton/node-events-listener#readme","devDependencies":{"mocha":"^3.3.0","sinon":"^2.1.0"},"gitHead":"16ff5ff1a3a9d050166e4f85649e5e58ce13467f","_id":"events-listener@1.0.2","_shasum":"2b2deaf2e92216dc4d3457aea37dc37132f7633c","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.10.0","_npmUser":{"name":"jwalton","email":"npm@lucid.thedreaming.org"},"dist":{"shasum":"2b2deaf2e92216dc4d3457aea37dc37132f7633c","tarball":"https://registry.npmjs.org/events-listener/-/events-listener-1.0.2.tgz","integrity":"sha512-pgsTo6UqOaJiGIgdLxn6R38KyBN1j+yrxildOKmzumgEaqCmyMhGwBVC2ba/KrI/LExl3v15QKHYqkZIiu8vMA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDMBVpk64nCk0ucK3r+Qo3SV0LNF03JEBA1okZHI8U0TgIgWc+8PD+s1A2IqcYc32OejvorNxc9hiMVS2FlD3bIEXM="}]},"maintainers":[{"name":"jwalton","email":"npm@lucid.thedreaming.org"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/events-listener-1.0.2.tgz_1493587342684_0.1583166120108217"},"directories":{}},"1.1.0":{"name":"events-listener","version":"1.1.0","description":"Listen to events from a Node.js EventEmitter.","main":"index.js","types":"index.d.ts","scripts":{"test":"mocha","prepublishOnly":"mocha"},"repository":{"type":"git","url":"git+https://github.com/jwalton/node-events-listener.git"},"keywords":["events","EventEmitter","listenTo","node","node.js","stopListening"],"author":{"name":"Jason Walton"},"license":"MIT","bugs":{"url":"https://github.com/jwalton/node-events-listener/issues"},"homepage":"https://github.com/jwalton/node-events-listener#readme","devDependencies":{"mocha":"^5.1.1","sinon":"^4.5.0"},"gitHead":"a99bec3afcdf033504277ed48ca12e433884d9d1","_id":"events-listener@1.1.0","_npmVersion":"5.8.0","_nodeVersion":"8.11.1","_npmUser":{"name":"jwalton","email":"npm@lucid.thedreaming.org"},"dist":{"integrity":"sha512-Kd3EgYfODHueq6GzVfs/VUolh2EgJsS8hkO3KpnDrxVjU3eq63eXM2ujXkhPP+OkeUOhL8CxdfZbQXzryb5C4g==","shasum":"dd49b4628480eba58fde31b870ee346b3990b349","tarball":"https://registry.npmjs.org/events-listener/-/events-listener-1.1.0.tgz","fileCount":5,"unpackedSize":6671,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa2AEtCRA9TVsSAnZWagAAMSYP+wTYRsBqdKJozVXyGJff\nGyvyDuBltzAowVfqaWNA+5MY9eEb10QxFfILQW0JqS17hDDnROsHwUmQKPXn\nfyM7DpQw4nFp4i7GxPZB5z/6kMGildC9bW6olWtoQ3Uj0kAgH+p4qCKFBr1P\nRZ/UErl0+Y5W5oRDWexQ2zj0QFIAyKwqYlAd5GAGvxMzNsrU4MLjWRn2aXSf\n0dBuHXtmb8LX9pGnQh+jYhGAC/LetyC7JtwV7WJeFB1TEv6B0CsmfJUixSSJ\n35rZySrdYDVYxJbkUvPe393kmo1nX3PEJIi2R2JbndNGr7R9gyf3pX1A9TbZ\nn1HrzkUXMJmxJnLIwVai+n0rlEUkK3s4MXXUbYUDmzY+db2J3sWbiyGPcugN\nGt/4dRyV1lxP+MRtIzem9KjCSiBupBXVV+yn71emmB+T4t0x3V/E1Gidhgq/\nbW8ea6JkOji50HsenV7XGCSPNQBYWoVbXZStvsVQx9va1DfLn8+kQ8j2SzRc\nkvmjzh2TWm2LA8xDrPS3X9v9RFtYXwuxUQVd3OzVJ0BZHwXViQ0WCR7fQXNS\ncNHLUl4HdHmr7ii6Wq6wJng2OyyrxYr6pn++BD3pYscjEi8k0RIv848y4UXF\nLRnIysFI4WY1GSKqIIuk3rf91TRRYGS6IyCNQr+uv0KSP7CyFDWWKEpEKSnK\n+g3d\r\n=pCr6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFetwq4hPnjWoQmMdLRx6NZAs00BX8VweOF3foz/oupPAiBIc6dKza4kPeFhhUhzmwRoz0g2X5tYz91i+JmlEle9Gw=="}]},"maintainers":[{"name":"jwalton","email":"npm@lucid.thedreaming.org"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/events-listener_1.1.0_1524105516253_0.7257975076262573"},"_hasShrinkwrap":false}},"readme":"Node.js provides the `events` modules, which provides `EventEmitter`.  This modules provides `EventListener`,\nan object that can listen for events.\n\nThis was heavily inspired by [Backbone](http://backbonejs.org/)'s `listenTo()` and `stopListening()` functions.\nThe idea is to make it easy to de-regster an event listener when you're done with it.\n\nSupports Node.js 0.12 and up.\n\nEvent Listener Memory Leaks\n===========================\n\n```js\nimport EventEmitter from 'events';\n\nclass Widget() {\n    constructor(emitter) {\n        emitter.on('error', err => this.close());\n    }\n    ...\n}\n\nlet emitter = new EventEmitter();\n\nlet widget = new Widget(emitter);\n// Do some stuff with `widget`.  When we're done with it, clear the reference to\n// `widget` so the garbage collector can free it.\nwidget = null;\n```\n\nThe code above creates a pretty common memory leak in node.js apps; the problem in the above is that when we call\n`emitter.on('error', ...)`, we add the function we pass in to the EventEmitter's list of events to call, which\nmeans EventEmitter has a reference to the handler function.  But, the handler function is an arrow function,\nwhich binds `this`, which means the handler function has a reference to `widget`.  When we set `widget = null`,\nthe `Widget` object will never be garbage collected, because `emitter` still has a reference to it.\n\nOne way to solve this problem is to call `emitter.removeListener('error', handler)`, but note that the function\nwe passed to `emitter.on(...)` was not `this.close()`, so we can't call `emitter.removeListener('error', this.close)`.\nWe need to keep a reference to the anonymous arrow function we passed in to `emitter.on()`.\n\n`EventListener`'s job is to keep track of these references for you:\n\n\n```js\nimport EventEmitter from 'events';\nimport EventListener from 'events-listener';\n\nclass Widget() {\n    constructor(emitter) {\n        this.listener = new EventListener();\n        this.listener.listenTo(emitter, 'error', err => this.close());\n    }\n\n    destroy() {\n        this.listener.stopListening();\n    }\n    ...\n}\n\nlet emitter = new EventEmitter();\n\nlet widget = new Widget(emitter);\n\n// Do some stuff with `widget`.\n\nwidget.destroy();\nwidget = null;\n```\n\n\n\nAPI\n===\n\n### class EventListener\n\n#### EventListener.listenTo(emitter, event, handler)\n\nSimilar to calling `emitter.on(event, handler)`.\n\n#### EventListener.listenToOnce(emitter, event, handler)\n\nSimilar to calling `emitter.once(event, handler)`.\n\n#### EventListener.stopListening([emitter,] [event,] [handler]);\n\nStop listening to some or all events that were registered with calls to `listenTo()` or `listenToOnce()`.\n\nIf all three arguments are passed, this is similar to calling `emitter.removeListener(handler)`.\n\nIf no arguments are passed, then this will remove all listeners that have been registered on this listener.\nIf an `emitter` is passed, this will remove all listeners that have been registered on the specific emitter.\nIf `emitter` and `event` are passed, then this will remove all listeners from the specific emitter that were\nregistered for the specific event.\n","maintainers":[{"name":"jwalton","email":"npm@lucid.thedreaming.org"}],"time":{"modified":"2022-06-17T21:36:09.083Z","created":"2017-04-30T19:25:33.083Z","1.0.0":"2017-04-30T19:25:33.083Z","1.0.1":"2017-04-30T21:00:31.888Z","1.0.2":"2017-04-30T21:22:23.300Z","1.1.0":"2018-04-19T02:38:36.807Z"},"homepage":"https://github.com/jwalton/node-events-listener#readme","keywords":["events","EventEmitter","listenTo","node","node.js","stopListening"],"repository":{"type":"git","url":"git+https://github.com/jwalton/node-events-listener.git"},"author":{"name":"Jason Walton"},"bugs":{"url":"https://github.com/jwalton/node-events-listener/issues"},"license":"MIT","readmeFilename":"README.md"}