{"_id":"@azasypkin/event-dispatcher","_rev":"2-6c889e1ed8f8be3b564384001ea61a16","name":"@azasypkin/event-dispatcher","description":"Simple ES6 pure Javascript event dispatcher.","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@azasypkin/event-dispatcher","version":"1.0.0","description":"Simple ES6 pure Javascript event dispatcher.","main":"./bin/event-dispatcher.es2016.js","directories":{"test":"tests"},"scripts":{"build":"gulp","test":"NODE_ENV=test karma start --single-run","codecov":"codecov"},"repository":{"type":"git","url":"git+https://github.com/azasypkin/event-dispatcher.git"},"keywords":["events","event","dispatcher","bus"],"author":{"name":"Aleh Zasypkin"},"license":"MIT","bugs":{"url":"https://github.com/azasypkin/event-dispatcher/issues"},"homepage":"https://github.com/azasypkin/event-dispatcher#readme","devDependencies":{"babel-cli":"^6.24.0","babel-core":"^6.24.0","babel-loader":"^6.4.1","babel-plugin-istanbul":"^4.0.0","babel-preset-es2015":"^6.24.0","chai":"^3.5.0","codecov":"^2.1.0","eslint":"^3.17.1","gulp":"^3.9.1","gulp-eslint":"^3.0.1","gulp-rename":"^1.2.2","karma":"^1.5.0","karma-chai":"^0.1.0","karma-chrome-launcher":"^2.0.0","karma-coverage":"^1.1.1","karma-firefox-launcher":"^1.0.1","karma-mocha":"^1.3.0","karma-mocha-reporter":"^2.2.2","karma-sinon-chai":"^1.2.4","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^2.0.3","mocha":"^3.2.0","run-sequence":"^1.2.2","sinon":"^2.0.0","sinon-chai":"^2.8.0","webpack":"^2.2.1","webpack-stream":"^3.2.0"},"gitHead":"a3e01c7eb6d9d91d83050aaee8d7f57bbb5227c9","_id":"@azasypkin/event-dispatcher@1.0.0","_shasum":"fb1ab61ab137f19e5bd548c39cd0bdd13b77d480","_from":".","_npmVersion":"4.4.1","_nodeVersion":"7.7.3","_npmUser":{"name":"azasypkin","email":"aleh.zasypkin@gmail.com"},"dist":{"shasum":"fb1ab61ab137f19e5bd548c39cd0bdd13b77d480","tarball":"https://registry.npmjs.org/@azasypkin/event-dispatcher/-/event-dispatcher-1.0.0.tgz","integrity":"sha512-zoMf9Jma/LDUBmJhhnP4HcZJgBY+cMhW1As6vgl3o4C4YFHIMV9OwSbipEOH9ENKB0ph6ZExnVM2bT6ta6uDWg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHW/qGjk5YwNsUmuZKo1lQasIkt3PukgwEC/RJ9zn62kAiEAv3HlDelqj032c4Pz9AEEUqKFnwMprOwZVneOHYZr5EM="}]},"maintainers":[{"name":"azasypkin","email":"aleh.zasypkin@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/event-dispatcher-1.0.0.tgz_1490097805569_0.9249343832489103"}}},"readme":"# Event Dispatcher\n\n[![Build Status](https://travis-ci.org/azasypkin/event-dispatcher.svg?branch=master)](https://travis-ci.org/azasypkin/event-dispatcher)\n[![codecov.io](http://codecov.io/github/azasypkin/event-dispatcher/coverage.svg?branch=master)](http://codecov.io/github/azasypkin/event-dispatcher?branch=master)\n[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://raw.githubusercontent.com/azasypkin/event-dispatcher/master/LICENSE)\n\nThis file provides a helper to add custom events to any object.\n\n# Usage\n\nIn order to use this functionality with any object consumer should pick one of the following approaches: plain old \n`mixin` or ES6 Class `extends`approach:\n\n```js\nclass Obj extends EventDispatcher {}\nconst obj = new Obj();\n```\n\nOr `mixin` approach:\n```js\nconst obj = EventDispatcher.mixin({});\n```\n\nA list of events can be optionally provided and it is recommended to do so. If a list is provided then only the events \npresent in the list will be allowed. Using other unknown events will cause other functions to throw an error:\n```js\nclass Obj extends EventDispatcher {\n  constructor() { \n    super(['somethinghappened', 'somethingelsehappened']); \n  }\n}\nconst obj = new Obj();\n```\n\nOr `mixin` approach:\n```js\nconst obj = EventDispatcher.mixin({ ... }, ['somethinghappened', 'somethingelsehappened']);\n```\n\nThe object will have five new methods: `on`, `once`, `off`, `offAll` and `emit`. Use `on` to register a new \nevent-handler:\n```js\nobj.on(\"somethinghappened\", function onSomethingHappened() { ... });\n```\n\nIf the same event-handler is added multiple times then only one will be registered, e.g.:\n```js\nfunction onSomethingHappened() { ... }\nobj.on(\"somethinghappened\", onSomethingHappened);\nobj.on(\"somethinghappened\", onSomethingHappened); // Does nothing\n```\n\nUse `off` to remove a registered listener:\n```js\nobj.off(\"somethinghappened\", onSomethingHappened);\n```\n\nUse `once` to register a one-time event-handler: it will be automatically unregistered after being called.\n```js\nobj.once(\"somethinghappened\", function onSomethingHappened() { ... });\n```\n\nAnd use `offAll` to remove all registered event listeners for the specified event:\n```js\nobj.offAll(\"somethinghappened\");\n```\n\nWhen used without parameters `offAll` removes all registered event handlers, this can be useful when writing unit-tests.\n\nFinally use 'emit' to send an event to the registered handlers:\n```js\nobj.emit(\"somethinghappened\");\n```\n\nAn optional parameter can be passed to 'emit' to be passed to the registered handlers:\n```js\nobj.emit(\"somethinghappened\", 123);\n```\n","maintainers":[{"name":"azasypkin","email":"aleh.zasypkin@gmail.com"}],"time":{"modified":"2022-06-12T15:00:11.689Z","created":"2017-03-21T12:03:27.683Z","1.0.0":"2017-03-21T12:03:27.683Z"},"homepage":"https://github.com/azasypkin/event-dispatcher#readme","keywords":["events","event","dispatcher","bus"],"repository":{"type":"git","url":"git+https://github.com/azasypkin/event-dispatcher.git"},"author":{"name":"Aleh Zasypkin"},"bugs":{"url":"https://github.com/azasypkin/event-dispatcher/issues"},"license":"MIT","readmeFilename":"README.md"}