{"id":20759832,"url":"https://github.com/owsas/pubsub-replay","last_synced_at":"2025-07-18T00:09:57.141Z","repository":{"id":27434601,"uuid":"113889092","full_name":"owsas/pubsub-replay","owner":"owsas","description":"Useful for when you need to replay previously sent events on a Pubsub network in JS. Based on `pubsub-js`.","archived":false,"fork":false,"pushed_at":"2025-06-25T03:04:49.000Z","size":171,"stargazers_count":3,"open_issues_count":21,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-29T03:22:48.253Z","etag":null,"topics":["events","javascript","pubsub"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/owsas.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-12-11T17:36:57.000Z","updated_at":"2025-04-05T04:15:12.000Z","dependencies_parsed_at":"2023-01-14T06:44:39.163Z","dependency_job_id":"191f8635-2a0a-49a7-9f72-1dad55393fde","html_url":"https://github.com/owsas/pubsub-replay","commit_stats":{"total_commits":20,"total_committers":5,"mean_commits":4.0,"dds":"0.44999999999999996","last_synced_commit":"f69646f85d322f9054bc4e028c995d2c289c6068"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/owsas/pubsub-replay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fpubsub-replay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fpubsub-replay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fpubsub-replay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fpubsub-replay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/owsas","download_url":"https://codeload.github.com/owsas/pubsub-replay/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owsas%2Fpubsub-replay/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265683689,"owners_count":23810879,"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":["events","javascript","pubsub"],"created_at":"2024-11-17T10:08:27.962Z","updated_at":"2025-07-18T00:09:57.092Z","avatar_url":"https://github.com/owsas.png","language":"TypeScript","funding_links":["https://patreon.com/owsas"],"categories":[],"sub_categories":[],"readme":"# Pubsub replay\n\n![](https://travis-ci.org/owsas/pubsub-replay.svg?branch=master)\n\nUseful for when you need to replay the last sent event on a Pubsub network. Based on `pubsub-js`.\n\n## Installation\n\n`npm install pubsub-replay`\n\n## Usage\n\n```ts\n// with es6\nimport { PubsubReplay } from 'pubsub-replay';\n\n// with es5\nconst { PubsubReplay } = require('pubsub-replay');\n```\n\n### Publishing and Subscribing\nThis is done with the same API of `pubsub-js`.\n\n```ts\nPubsubReplay.subscribe('testChannel', (channelName, data) =\u003e {\n  console.log(data); // { myData: true }\n});\n\nPubsubReplay.publish('testChannel', { myData: true });\n```\n\n### Subscribing to previous events\nYou may want to subscribe to a channel, and get the previous message that was sent before you subscribed.\n\nFor example, when an application starts, you may want to check your local database, see if there is an user connected and publish the current user in the 'user' channel.\n\nExample\n```ts\nconst user = await getTheCurrentLoggedInUser();\nPubsubReplay.publish('user', user);\n```\n\nLater on, you may want to read if the user is logged in a 'My Account' page, and subscribe to updates in the user channel.\n\nYou would do this by doing the following:\n```ts\n// MyAccountPage.js\nlet user = await getTheCurrentLoggedInUser();\nPubsubReplay.subscribe('user', (channelName, data) =\u003e {\n  user = data;\n});\n```\n\nThe value proposition of this library in this case is not having to get the current user from a database, a network call, or local storage every time you want to get it.\n\nInstead you would do:\n\n```ts\n// MyAccountPage.js\nlet user;\nPubsubReplay.subscribe('user', (channelName, data) =\u003e {\n  user = data;\n}, true); // the true means replay the last event\n```\n\n### Motivation\n\nI created this module because I am working with ReactJS. Quite frequently,  when I was creating modules, I had to import several libraries to make a network call or read a local database with the user in its last state.\n\nThat's when I discovered `pubsub-js`, to subscribe to the user changes across the life cycle of the application, thus avoiding to read from the database by long-polling. But, I still had to import the libraries and make the network requests to get the current user in the app.\n\nSo, I thought there should be a way in which I could subscribe to the user changes, and get the last user that was sent in the channel, without having to long poll, or to make network requests on each of the components that show the user info.\n\n\n## Dev Features\n* Testing with Jest\n* Linting out of the box (checks the style of your code), with TSLint\n* Build, prepublish and other scripts to help you to develop\n* Works with Typescript: Static typing for your JS Applications, reducing amount of runtime errors\n* Coverage out of the box, thanks to Jest\n* Uses deterministic module resolving, with Yarn\n\n## Credits\n\nDeveloped by Juan Camilo Guarín Peñaranda,  \nOtherwise SAS, Colombia  \n2017\n\n## License \n\nMIT.\n\n## Support us on Patreon\n[![patreon](./repo/patreon.png)](https://patreon.com/owsas)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowsas%2Fpubsub-replay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowsas%2Fpubsub-replay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowsas%2Fpubsub-replay/lists"}