{"id":18867627,"url":"https://github.com/simplrjs/action-emitter","last_synced_at":"2026-04-25T23:33:33.144Z","repository":{"id":57172742,"uuid":"87348847","full_name":"SimplrJS/action-emitter","owner":"SimplrJS","description":"Action emitter based on fbemitter. Instead of string event types we use classes (functions).","archived":false,"fork":false,"pushed_at":"2017-04-10T23:23:29.000Z","size":58,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T17:41:36.109Z","etag":null,"topics":["action","action-emitter","emitter","event","eventemitter","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/SimplrJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-05T19:32:07.000Z","updated_at":"2017-10-18T22:06:17.000Z","dependencies_parsed_at":"2022-08-24T14:41:07.943Z","dependency_job_id":null,"html_url":"https://github.com/SimplrJS/action-emitter","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimplrJS%2Faction-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimplrJS%2Faction-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimplrJS%2Faction-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimplrJS%2Faction-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimplrJS","download_url":"https://codeload.github.com/SimplrJS/action-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239816478,"owners_count":19701753,"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":["action","action-emitter","emitter","event","eventemitter","typescript"],"created_at":"2024-11-08T05:10:28.114Z","updated_at":"2026-02-13T14:30:19.564Z","avatar_url":"https://github.com/SimplrJS.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# action-emitter\nAction emitter based on [fbemitter](https://github.com/facebook/emitter). Instead of string event types we use classes (functions).\nThe package is most useful when used with [TypeScript](http://typescriptlang.org).\n\n[![Build Status](https://travis-ci.org/SimplrJS/action-emitter.svg?branch=master)](https://travis-ci.org/SimplrJS/action-emitter)\n[![NPM version](http://img.shields.io/npm/v/action-emitter.svg)](https://www.npmjs.com/package/action-emitter) [![dependencies Status](https://david-dm.org/simplrjs/action-emitter/status.svg)](https://david-dm.org/simplrjs/action-emitter) [![devDependencies Status](https://david-dm.org/simplrjs/action-emitter/dev-status.svg)](https://david-dm.org/simplrjs/action-emitter?type=dev)\n\n\n## Get started\n```cmd\n$ npm install action-emitter --save-dev\n```\n\n## Usage\nFirst import the `action-emitter` package and then create a new emitter instance.\n```ts\nimport { ActionEmitter } from \"action-emitter\";\nconst Emitter = new ActionEmitter();\n```\n\n\n## API\n\n### `constructor(): void`\nCreate a new emitter instance.\n\n#### Emitter construction example:\n```ts\nconst Emitter = new ActionEmitter();\n```\n\n### `addListener(actionClass, callback): EventSubscription`\nRegister a specific callback to be called on a particular action event. A subscription is returned that can be called to remove the listener.\n\n#### Arguments\n| Argument      | Type                        | Description                 |\n|---------------|-----------------------------|-----------------------------|\n| `actionClass` | `Function`                  | Action class function.      |\n| `callback`    | `(action: TAction) =\u003e void` | Listener callback function. |\n\n\n#### Add listener example:\n```ts\nclass MyAction {\n    constructor(private value: string) { }\n    public get Value() {\n        return this.value;\n    }\n}\n\nlet subsciption = Emitter.addListener\u003cMyAction\u003e(MyAction, action =\u003e {\n    console.log(action.Value);\n});\n```\n\n\n### `once(actionClass, callback): EventSubscription`\nSimilar to `addListener()` but the callback is removed after it is invoked once. A subscription is returned that can be called to remove the listener.\n\n#### Arguments\n| Argument      | Type                        | Description                 |\n|---------------|-----------------------------|-----------------------------|\n| `actionClass` | `Function`                  | Action class function.      |\n| `callback`    | `(action: TAction) =\u003e void` | Listener callback function. |\n\n#### Add once listener example:\n```ts\nclass MyAction {\n    constructor(private value: string) { }\n    public get Value() {\n        return this.value;\n    }\n}\n\nlet subsciption = Emitter.once\u003cMyAction\u003e(MyAction, action =\u003e {\n    console.log(action.Value);\n});\n```\n\n\n### `removeAllListeners(actionClass): void`\nRemoves all of the registered listeners. If provide `actionClass`, only listeners for that action class are removed.\n\n#### Arguments\n| Argument                    | Type        | Description                 |\n|-----------------------------|-------------|-----------------------------|\n| `actionClass`\u003csup\u003e[*]\u003c/sup\u003e | `Function`  | Action class function.      |\n\n\u003csup\u003e[*]\u003c/sup\u003e - optional.\n\n#### Remove all listeners example:\n```ts\nclass MyAction {\n    constructor(private value: string) { }\n    public get Value() {\n        return this.value;\n    }\n}\n\nEmitter.removeAllListeners(MyAction);\n// Or\nEmitter.removeAllListeners();\n```\n\n\n### `listeners(actionClass): Function[]`\nReturns an array of listeners that are currently registered for the given action class.\n\n#### Arguments\n| Argument      | Type       | Description                 |\n|---------------|------------|-----------------------------|\n| `actionClass` | `Function` | Action class function.      |\n\n\n#### Listeners list example:\n```ts\nlet listenersList = Emitter.listeners();\n```\n\n\n### `listenersCount(actionClass): number`\nReturn listeners count that are currently registered for the given action class. \nIf action class is not specified, method will return all registered action listeners count.\n\n#### Arguments\n| Argument                    | Type       | Description                 |\n|-----------------------------|------------|-----------------------------|\n| `actionClass`\u003csup\u003e[*]\u003c/sup\u003e | `Function` | Action class function.      |\n\n\u003csup\u003e[*]\u003c/sup\u003e - optional.\n\n#### Listeners list example:\n```ts\nclass MyAction {\n    constructor(private value: string) { }\n    public get Value() {\n        return this.value;\n    }\n}\n\nlet globalListenersCount = Emitter.listenersCount();\n// or \nlet listenersCount = Emitter.listenersCount(MyAction);\n```\n\n\n### `emit(action): void`\nEmits an action event with the given data. All callbacks that are listening to the particular action event will be notified.\n\n#### Arguments\n| Argument      | Type      | Description                 |\n|---------------|-----------|-----------------------------|\n| `action`      | `TAction` | Action class instance.      |\n\n\n#### Action emit example:\n```ts\nclass MyAction {\n    constructor(private value: string) { }\n    public get Value() {\n        return this.value;\n    }\n}\n\nEmitter.emit\u003cMyAction\u003e(new MyAction(\"value\"));\n//or \nEmitter.emit(new MyAction(\"value\"));\n```\n\n## Debuging\nYou can listen to all actions with `AnyAction` class.\n```ts\nimport { AnyAction } from \"action-emitter\";\nEmitter.addListener(AnyAction, anyAction =\u003e {\n    let actionInstance = anyAction.Action;\n    console.log(actionInstance);\n});\n```\n\n\n## License\nReleased under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplrjs%2Faction-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplrjs%2Faction-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplrjs%2Faction-emitter/lists"}