{"id":16189367,"url":"https://github.com/caolan/events","last_synced_at":"2025-03-19T03:30:52.290Z","repository":{"id":65991224,"uuid":"6505080","full_name":"caolan/events","owner":"caolan","description":"Browser port of the node.js events module","archived":false,"fork":false,"pushed_at":"2012-11-02T11:21:25.000Z","size":136,"stargazers_count":9,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T15:04:40.388Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caolan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-02T11:18:17.000Z","updated_at":"2024-12-25T13:28:53.000Z","dependencies_parsed_at":"2023-02-19T21:00:37.789Z","dependency_job_id":null,"html_url":"https://github.com/caolan/events","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fevents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fevents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fevents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caolan%2Fevents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caolan","download_url":"https://codeload.github.com/caolan/events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243965774,"owners_count":20375917,"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":[],"created_at":"2024-10-10T07:35:13.921Z","updated_at":"2025-03-19T03:30:51.932Z","avatar_url":"https://github.com/caolan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Events module\n\nThis is a AMD port of the node.js events module. Many objects and\nmodules emit events and these are instances of events.EventEmitter.\n\n\nFunctions can be attached to objects, to be executed when an event is\nemitted. These functions are called listeners.\n\n\n### API\n\n\n#### events.EventEmitter\n\n\nWhen an EventEmitter instance experiences an error, the typical action is to\nemit an 'error' event. Error events are treated as a special case. If there\nis no listener for it, then the default action is for the error to throw.\n\nAll EventEmitters emit the event 'newListener' when new listeners are added.\n\n```javascript\ndefine('myModule', ['events'], function(events) {\n\n// create an event emitter\nvar emitter = new events.EventEmitter();\n\n});\n```\n\n\n#### emitter.setMaxListeners(n)\n\nBy default EventEmitters will print a warning if more than 10 listeners are\nadded for a particular event. This is a useful default which helps finding\nmemory leaks. Obviously not all Emitters should be limited to 10. This\nfunction allows that to be increased. Set to zero for unlimited.\n\n* __n__ - _Number_ - The maximum number of listeners\n\n\n#### emitter.emit(event, [arg1], [arg2], [...])\n\nExecute each of the listeners in order with the supplied arguments.\n\n* __event__ - _String_ - The event name/id to fire\n\n\n#### emitter.on(event, listener) | emitter.addListener(event, listener)\n\nAdds a listener to the end of the listeners array for the specified event.\n\n* __event__ - _String_ - The event name/id to listen for\n* __listener__ - _Function_ - The function to bind to the event\n\n```javascript\nsession.on('change', function (userCtx) {\n    console.log('session changed!');\n});\n```\n\n\n#### emitter.once(event, listener)\n\nAdds a one time listener for the event. This listener is invoked only the\nnext time the event is fired, after which it is removed.\n\n* __event-__ - _String_ - The event name/id to listen for\n* __listener__ - _Function_ - The function to bind to the event\n\n```javascript\ndb.once('unauthorized', function (req) {\n    // this event listener will fire once, then be unbound\n});\n```\n\n\n#### emitter.removeListener(event, listener)\n\nRemove a listener from the listener array for the specified event. Caution:\nchanges array indices in the listener array behind the listener.\n\n* __event__ - _String_ - The event name/id to remove the listener from\n* __listener__ - _Function_ - The listener function to remove\n\n```javascript\nvar callback = function (init) {\n    console.log('duality app loaded');\n};\ndevents.on('init', callback);\n// ...\ndevents.removeListener('init', callback);\n```\n\n\n#### emitter.removeAllListeners([event])\n\nRemoves all listeners, or those of the specified event.\n\n* __event__ - _String_ - Event name/id to remove all listeners for (optional)\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* __events__ - _String_ - The event name/id to return listeners for\n\n```javascript\nsession.on('change', function (stream) {\n    console.log('session changed');\n});\nconsole.log(util.inspect(session.listeners('change'))); // [ [Function] ]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fevents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaolan%2Fevents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaolan%2Fevents/lists"}