{"id":19009187,"url":"https://github.com/gamtiq/neva","last_synced_at":"2026-04-23T21:30:16.501Z","repository":{"id":55975636,"uuid":"88367843","full_name":"gamtiq/neva","owner":"gamtiq","description":"Simple library to work with custom events","archived":false,"fork":false,"pushed_at":"2021-02-23T17:48:35.000Z","size":850,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-21T09:33:39.592Z","etag":null,"topics":["dispatch","emitter","event","event-handler","eventbus","eventemitter","listener","pub-sub","subscription"],"latest_commit_sha":null,"homepage":"https://gamtiq.github.io/neva/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gamtiq.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-15T18:51:31.000Z","updated_at":"2021-02-23T17:46:13.000Z","dependencies_parsed_at":"2022-08-15T10:40:29.433Z","dependency_job_id":null,"html_url":"https://github.com/gamtiq/neva","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamtiq%2Fneva","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamtiq%2Fneva/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamtiq%2Fneva/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gamtiq%2Fneva/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gamtiq","download_url":"https://codeload.github.com/gamtiq/neva/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240035944,"owners_count":19737613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dispatch","emitter","event","event-handler","eventbus","eventemitter","listener","pub-sub","subscription"],"created_at":"2024-11-08T19:07:04.198Z","updated_at":"2026-04-23T21:30:16.441Z","avatar_url":"https://github.com/gamtiq.png","language":"JavaScript","readme":"# neva \u003ca name=\"start\"\u003e\u003c/a\u003e\n\nSimple library to work with custom events.\n\n[![NPM version](https://badge.fury.io/js/neva.png)](http://badge.fury.io/js/neva)\n[![Build Status](https://secure.travis-ci.org/gamtiq/neva.png?branch=master)](http://travis-ci.org/gamtiq/neva)\n[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)\n\n* Simple event emitter API: `on`, `off`, `emit`, `hasEventHandler`.\n* Event emitter API is chainable.\n* Events can be emitted with multiple attached parameters.\n* Data about emitted event are wrapped into an object with uniform structure that is passed to handlers.\n* Ability to add event handler that should be called just once.\n* Ability to enhance prototype of constructor function (class) with event emitter API (emitter methods can be mixed in `prototype`).\n* Available as ECMAScript 6/2015 module, CommonJS module or UMD.\n* Work in any ECMAScript 3+ environment (browsers, Node.js etc).\n* Small.\n\n## Table of contents\n\n* [Installation](#install)\n* [Usage](#usage)\n* [Examples](#examples)\n* [API](#api)\n* [Contributing](#contributing)\n* [License](#license)\n\n## Installation \u003ca name=\"install\"\u003e\u003c/a\u003e [\u0026#x2191;](#start)\n\n### Node\n\n    npm install neva\n\n### [Bower](https://bower.io)\n\n    bower install neva\n\n### AMD, \u0026lt;script\u0026gt;\n\nUse `dist/neva.js` or `dist/neva.min.js` (minified version).\n\n## Usage \u003ca name=\"usage\"\u003e\u003c/a\u003e [\u0026#x2191;](#start)\n\n### ECMAScript 6+\n\n```js\nimport getEmitter from 'neva';\n```\n\n### Node\n\n```js\nconst getEmitter = require('neva').getEmitter;\n```\n\n### AMD\n\n```js\ndefine(['path/to/dist/neva.js'], function(neva) {\n    const getEmitter = neva.getEmitter;\n});\n```\n\n### Bower, \u0026lt;script\u0026gt;\n\n```html\n\u003c!-- Use bower_components/neva/dist/neva.js if the library was installed by Bower --\u003e\n\u003cscript type=\"text/javascript\" src=\"path/to/dist/neva.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n    // neva is available via neva field of window object\n    const getEmitter = neva.getEmitter;\n\u003c/script\u003e\n```\n\n### Examples \u003ca name=\"examples\"\u003e\u003c/a\u003e [\u0026#x2191;](#start)\n\n```js\nconst emitter = getEmitter();\nconst eventHandler = (event) =\u003e {\n    console.log('eventHandler: event type -', event.type, ', data -', event.data);\n};\nconst obj = {\n    name: 'obj',\n    handler(event) {\n        console.log(`${this.name}.handler: event type -`, event.type, ', params -', event.params);\n    }\n};\nfunction onceHandler(event) {\n    console.log('onceHandler: event type -', event.type, ', data -', event.data);\n}\n\nemitter.on(['event1', 'event2'], eventHandler)\n        .on('event1', obj.handler, obj)\n        .on('event2', onceHandler, null, {once: true});\n\nemitter.emit('event1', 1, 2, 3)\n        .emit({type: 'event2', data: 'some data', qty: 8});\n// The following will be printed into console:\n// eventHandler: event type - event1 , data - 1\n// obj.handler: event type - event1 , params - Array [ 1, 2, 3 ]\n// eventHandler: event type - event2 , data - some data\n// onceHandler: event type - event2 , data - some data\n\nemitter.hasEventHandler('event1', eventHandler); // true\nemitter.hasEventHandler('event2', onceHandler); // false\n\nemitter.off('event1', eventHandler);\nemitter.hasEventHandler('event1', eventHandler); // false\nemitter.hasEventHandler('event1'); // true\n\nemitter.off('event1');\nemitter.hasEventHandler('event1'); // false\nemitter.hasEventHandler(); // true\n\nemitter.off();\nemitter.hasEventHandler(); // false\n\nclass SomeClass {\n    ...\n}\n// Add event emitter methods to class\ngetEmitter(SomeClass.prototype);\n```\n\n## API \u003ca name=\"api\"\u003e\u003c/a\u003e [\u0026#x2191;](#start)\n\n### getEmitter([target: Object]): EventEmitter\n\nCreate event emitter or add methods to work with events into specified object.\n\n`target` can be prototype of some constructor function (class).\n\n### EventEmitter API\n\n#### on(type: string | string[], handler: Function, [context: Object], [settings: HandlerSettings]): EventEmitter\n\nRegister a handler for the specified event type(s).\n\n#### off(type: string, handler: Function, [context: Object]): EventEmitter\n\nRemove the specified event handler.\n\n#### off(type: string): EventEmitter\n\nRemove all handlers for the given event type.\n\n#### off(): EventEmitter\n\nRemove all registered event handlers.\n\n#### emit(type: string, [param1: any, param2: any, ...]): EventEmitter\n\nCall all handlers for the specified event type.\n\nAn object with the following fields will be passed in each handler:\n* `type: string` - the event type (value of `type` parameter).\n* `params: Array` - list of additional parameters that are passed besides the event type (`[param1, param2, ...]`).\n* `data: any` - value of the second function's parameter (value of `params[0]`).\n\n#### emit({type: string, ...}): EventEmitter\n\nCall all handlers for the specified event type and pass the given object in each handler.\n\n#### hasEventHandler(type: string, handler: Function, [context: Object]): boolean\n\nCheck whether the specified event handler is registered.\n\n#### hasEventHandler(type: string): boolean\n\nCheck whether any handler for the specified event type is registered.\n\n#### hasEventHandler(): boolean\n\nCheck whether any event handler is registered.\n\nSee [`docs`](https://gamtiq.github.io/neva/) for details.\n\n## Contributing \u003ca name=\"contributing\"\u003e\u003c/a\u003e [\u0026#x2191;](#start)\nIn lieu of a formal styleguide, take care to maintain the existing coding style.\nAdd unit tests for any new or changed functionality.\nLint and test your code using [Grunt](http://gruntjs.com/).\n\n## License \u003ca name=\"license\"\u003e\u003c/a\u003e [\u0026#x2191;](#start)\nCopyright (c) 2017-2021 Denis Sikuler  \nLicensed under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamtiq%2Fneva","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgamtiq%2Fneva","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgamtiq%2Fneva/lists"}