{"id":19068440,"url":"https://github.com/bobbylite/telephone-ts","last_synced_at":"2025-04-28T13:25:05.968Z","repository":{"id":48022361,"uuid":"172995341","full_name":"bobbylite/telephone-ts","owner":"bobbylite","description":"Telephone-ts: The \"Event Emitter-less\" TypeScript Event Architecture.","archived":false,"fork":false,"pushed_at":"2021-08-10T22:11:22.000Z","size":8310,"stargazers_count":23,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T10:02:05.290Z","etag":null,"topics":["autowiring","dependency-injection","event-emitter","eventbus","events","inversifyjs","inversion-of-control","message","message-bus","message-queue","oop-principles","telephone","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bobbylite.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":"2019-02-27T21:46:06.000Z","updated_at":"2022-06-09T14:13:07.000Z","dependencies_parsed_at":"2022-08-12T16:51:07.216Z","dependency_job_id":null,"html_url":"https://github.com/bobbylite/telephone-ts","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/bobbylite%2Ftelephone-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbylite%2Ftelephone-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbylite%2Ftelephone-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbylite%2Ftelephone-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bobbylite","download_url":"https://codeload.github.com/bobbylite/telephone-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249428484,"owners_count":21270467,"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":["autowiring","dependency-injection","event-emitter","eventbus","events","inversifyjs","inversion-of-control","message","message-bus","message-queue","oop-principles","telephone","typescript"],"created_at":"2024-11-09T01:08:07.395Z","updated_at":"2025-04-18T04:32:27.603Z","avatar_url":"https://github.com/bobbylite.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# telephone-ts [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Telephone-ts%20TypeScript%20Architecture%20\u0026url=https://github.com/bobbylite/telephone-ts\u0026hashtags=Inversion-of-Control,Events,TypeScript,TelephoneTS)\nTelephone-ts is a \"Event Emitter-less\" TypeScript Event Architecture.  Without the use of the 'events' module from node, Telephone-ts is an OOP message bus that allows developers to easily register their TypeScript Event Handlers to listen to when an Event message is \"Shouted\" on the telephone line! \n\nSure, there are tons of great event modules... I found this way useful when trying to keep my code modular with InversifyJS, which is the IOC DI registering engine behind Telephone-ts. \n\n## Run example\nThere is a test script available to run to see how this repo works. \nRun the following in your terminal.\n\n### Clone the code \n```bash\ngit clone https://github.com/bobbylite/telephone-ts.git\ncd telephone-ts/\n```\n\n### Install dependencies\n```bash\nnpm install \nnpm run test\n```\n\n## How to use in project\n\n### Step 1\nCreate your Event Interfaces.  This will explain what you want your event to send over our line! \n```typescript\nexport interface IHelloEvent {\n    msg: string;\n}\n```\n\n### Step 2\nImplement your Event so you can have everything you need.  Maybe you want to setup a service for handling an event later?  \nIn this example we'll just use our greeting string we all love. \n```typescript \nexport class HelloEvent implements IHelloEvent {\n    public msg: string = \"Hello World!\";\n}\n```\n\n### Step 3 \nNext we'll create our event handler interfaces. This will explain what is needed to handle the event!\n```typescript \nexport interface IHelloHandler {\n    // anything you want your event handler to have.\n}\n```\n\n### Step 4\nThis is where we will implement our event handler.  We must make sure to inherit/extend the BaseHandler class provided. \n```typescript\nexport class HelloHandler extends BaseHandler\u003cIHelloEvent\u003e implements IHelloHandler {\n\n    public constructor() {\n        super();\n    }\n\n    protected HandleMessage(message: IHelloEvent) : IHelloEvent{\n        console.log(message);\n\n        return message;\n    }\n}\n```\n\n### Step 5\nWe now have everything we need to register, and emit events... Or create our quiet listening wire and shout on that wire! \nBoth Register and Call require the following: \nTelephonetsInstance.Register\u003cEventInterface\u003e(\"EventInterface\", HandlerClassReference);\nTelephonetsInstance.Call\u003cEventInterface\u003e(\"EventInterface\", new EventClass);\n```typescript\nconst sleep = (ms: number) =\u003e new Promise(resolve =\u003e setTimeout(resolve, ms));\n\nasync function Test() {\n    var telephonets = new Telephonets();\n\n    telephonets.Register\u003cINotHelloEvent\u003e(\"INotHelloEvent\", NotHelloHandler);\n    telephonets.Register\u003cIHelloEvent\u003e(\"IHelloEvent\", HelloHandler);\n\n\n    telephonets.Call\u003cIHelloEvent\u003e(\"IHelloEvent\", new HelloEvent); // outputs -\u003e HelloEvent { msg: 'Hello World!' }\n    await sleep(1000);\n    telephonets.Call\u003cINotHelloEvent\u003e(\"INotHelloEvent\", new NotHelloEvent); // outputs -\u003e NotHelloEvent { msg: 'Not Hello World!' }\n}\n```\n\n## Behind the scenes\nBehind the scenes we have two important files that really auto-wire up the events to the handlers.  These two files are the telephonets.ts and BaseHandler.ts.  telephonets uses InversifyJs' Container to auto-wire similar to how Autofac or other IOC libraries work.  The BaseHandler is what we need our custom handlers to inherit from to ensure the project is structured properly.  Take a look below.\n\n#### telephonets.ts\n```typescript\nexport class Telephonets implements ITelephonets {\n\n    private container: Container;\n\n    public constructor() {\n        this.container = new Container();\n    }\n\n    public Register\u003cT\u003e(symbolString: string, Handler: any) : void {\n        this.container.bind\u003cT\u003e(symbolString).to(Handler);\n    }\n\n    public Call\u003cT\u003e(symbolString: string, message: any) : void {\n        this.container.get\u003cIBaseHandler\u003cT\u003e\u003e(symbolString).ReceiveMessage(message);\n    }\n}\n```\n\n#### BaseHandler.ts\n```typescript\n@injectable()\nexport abstract class BaseHandler\u003cT\u003e implements IBaseHandler\u003cT\u003e {\n    public ReceiveMessage(injection: T) : void {\n        try {\n            this.HandleMessage(injection);\n        } catch(err) {\n            console.log(err);\n        }\n    }\n    protected abstract HandleMessage(message: T): T;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbylite%2Ftelephone-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobbylite%2Ftelephone-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbylite%2Ftelephone-ts/lists"}