{"id":19251351,"url":"https://github.com/springtype-org/st-bus","last_synced_at":"2025-07-31T18:06:44.073Z","repository":{"id":57369081,"uuid":"335783779","full_name":"springtype-org/st-bus","owner":"springtype-org","description":"~200 byte nano event bus library","archived":false,"fork":false,"pushed_at":"2021-02-04T01:38:23.000Z","size":208,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T12:17:38.009Z","etag":null,"topics":[],"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/springtype-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-03T23:32:15.000Z","updated_at":"2021-02-09T16:21:32.000Z","dependencies_parsed_at":"2022-09-15T21:31:02.970Z","dependency_job_id":null,"html_url":"https://github.com/springtype-org/st-bus","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/springtype-org%2Fst-bus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springtype-org%2Fst-bus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springtype-org%2Fst-bus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springtype-org%2Fst-bus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/springtype-org","download_url":"https://codeload.github.com/springtype-org/st-bus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240347763,"owners_count":19787230,"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-11-09T18:22:01.764Z","updated_at":"2025-02-23T16:40:42.442Z","avatar_url":"https://github.com/springtype-org.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eSpringType: st-bus\u003c/h1\u003e\n\n\u003e Nano event bus library\n\n[![Gitter](https://badges.gitter.im/springtype-official/springtype.svg)](https://gitter.im/springtype-official/springtype?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n\u003ch2 align=\"center\"\u003ePurpose\u003c/h2\u003e\n\nThis is an exremely tiny, yet powerful eventing library. `st-bus` makes it easy to decouple components. If one component wants to tell another component that something happend, `emit` is called. In another component, `on` is called to listen for such events.\n\n\u003ch2 align=\"center\"\u003eFeatures\u003c/h2\u003e\n\n- ✅ Implements a socket.io-like publish/subscribe API\n- ✅ Tiny: `136 byte` (best, brotli) - `267 byte` (worst, umd, gz)\n- ✅ Zero dependencies\n- ✅ First class TypeScript support\n- ✅ 100% Unit Test coverage\n\n\u003ch2 align=\"center\"\u003eHow to\u003c/h2\u003e\n\nThis is how `st-bus` is used:\n\n```tsx\nimport { tsx, render, Ref } from 'springtype';\nimport { $ } from 'st-query';\nimport { bus } from 'st-bus';\n\ninterface ChatMessage {\n  user: string;\n  time: number;\n  text: string;\n}\n\nconst TrollBox = () =\u003e {\n  const chatMessagesRef: Ref = {};\n\n  // local messages state\n  const msgs = [];\n\n  bus.on('chat:message', (event: ChatMessage) =\u003e {\n    // add message to local state\n    msgs.push(\n      \u003cdiv\u003e\n        \u003chr /\u003e\n        {new Date(event.time).toUTCString()}\n        \u003cbr /\u003e\n        \u003cstrong\u003e{event.user}: \u003c/strong\u003e\n        {event.text}\n      \u003c/div\u003e,\n    );\n\n    // re-render all messages\n    $(chatMessagesRef.current).html(\u003cdiv\u003e{msgs}\u003c/div\u003e);\n  });\n\n  return (\n    \u003cdiv\u003e\n      \u003ch3\u003eChat room:\u003c/h3\u003e\n      \u003cdiv ref={chatMessagesRef} /\u003e\n    \u003c/div\u003e\n  );\n};\n\nconst TrollInput = () =\u003e {\n  const chatMessageInputRef: Ref = {};\n\n  const sendMessage = () =\u003e {\n    bus.emit('chat:message', {\n      user: 'Anonymous',\n      time: Date.now(),\n      text: $(chatMessageInputRef.current).val(),\n    });\n    // reset input\n    $(chatMessageInputRef.current).val('');\n  };\n\n  return (\n    \u003cdiv style={{ borderTop: '2px solid #ccc', backgroundColor: '#eee', padding: 10, marginTop: 10 }}\u003e\n      \u003cinput\n        ref={chatMessageInputRef}\n        placeholder=\"Your message...\"\n        onKeyUp={(evt: KeyboardEvent) =\u003e {\n          if (evt.keyCode === 13) {\n            sendMessage();\n          }\n        }}\n        type=\"text\"\n      /\u003e\n      \u003cbutton type=\"button\" onClick={sendMessage}\u003e\n        Send\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n\nconst AlterEgoChat = () =\u003e (\n  \u003cfragment\u003e\n    \u003cTrollBox /\u003e\n    \u003cTrollInput /\u003e\n  \u003c/fragment\u003e\n);\n\nrender(\u003cAlterEgoChat /\u003e);\n```\n\n\u003ch2 align=\"center\"\u003eAPI\u003c/h2\u003e\n\nThe following contract is made between the webapp and `st-bus`:\n\n```typescript\nexport interface API {\n  subscribers: Array\u003cSubscriber | undefined\u003e;\n  on(topic: string, handler: EventHandler): number;\n  off(subscriberId: number): void;\n  emit(topic: string, event: any): void;\n}\n```\n\n\u003ch2 align=\"center\"\u003eBackers\u003c/h2\u003e\n\nThank you so much for supporting us financially! 🙏🏻😎🥳👍\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://avatars2.githubusercontent.com/u/17221813?v=4\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/jsdevtom\"\u003eTom\u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\n\u003ch2 align=\"center\"\u003eMaintainers\u003c/h2\u003e\n\n`st-bus` is brought to you by:\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\"\u003e\n        \u003cimg width=\"150\" height=\"150\"\n        src=\"https://avatars3.githubusercontent.com/u/454817?v=4\u0026s=150\"\u003e\n        \u003c/br\u003e\n        \u003ca href=\"https://github.com/kyr0\"\u003eAron Homberg\u003c/a\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003ctbody\u003e\n\u003c/table\u003e\n\n\u003ch2 align=\"center\"\u003eContributing\u003c/h2\u003e\n\nPlease help out to make this project even better and see your name added to the list of our\n[CONTRIBUTORS.md](./CONTRIBUTORS.md) :tada:\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringtype-org%2Fst-bus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspringtype-org%2Fst-bus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringtype-org%2Fst-bus/lists"}