{"id":15628042,"url":"https://github.com/sibiraj-s/capillaries","last_synced_at":"2025-04-28T19:45:00.292Z","repository":{"id":36011111,"uuid":"220798128","full_name":"sibiraj-s/capillaries","owner":"sibiraj-s","description":"⚡️ Javascript Events and Hooks","archived":false,"fork":false,"pushed_at":"2024-09-24T09:41:44.000Z","size":1960,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-23T02:36:54.380Z","etag":null,"topics":["async-events","capillaries","hooks","javascript-events"],"latest_commit_sha":null,"homepage":"https://npm.im/capillaries","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":"Unmaintained","scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sibiraj-s.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":["sibiraj-s"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2019-11-10T14:01:04.000Z","updated_at":"2024-09-24T09:41:40.000Z","dependencies_parsed_at":"2023-01-16T11:44:50.356Z","dependency_job_id":"f11ded50-832e-4a59-a317-5f1a15a3c451","html_url":"https://github.com/sibiraj-s/capillaries","commit_stats":{"total_commits":144,"total_committers":3,"mean_commits":48.0,"dds":0.0625,"last_synced_commit":"0650d3e77b79cea7df356ccbab9df411f6f0e288"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sibiraj-s%2Fcapillaries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sibiraj-s%2Fcapillaries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sibiraj-s%2Fcapillaries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sibiraj-s%2Fcapillaries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sibiraj-s","download_url":"https://codeload.github.com/sibiraj-s/capillaries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233042725,"owners_count":18616064,"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":["async-events","capillaries","hooks","javascript-events"],"created_at":"2024-10-03T10:20:36.714Z","updated_at":"2025-01-08T14:16:37.527Z","avatar_url":"https://github.com/sibiraj-s.png","language":"TypeScript","funding_links":["https://github.com/sponsors/sibiraj-s"],"categories":[],"sub_categories":[],"readme":"# Capillaries [![Tests](https://github.com/sibiraj-s/capillaries/workflows/Tests/badge.svg)](https://github.com/sibiraj-s/capillaries/actions)\n\n\u003e Javascript Events and Hooks\n\n## Getting Started\n\n### Installation\n\nInstallation can be done via package managers such as [npm] or [yarn]\n\n```bash\n% npm install capillaries\n\n# or\n\n% yarn add capillaries\n```\n\n### Events\n\n```js\nimport { Events } from 'capillaries';\n\nconst event = new Events();\n\nconst listener = function (payload) {\n  console.log('Event Received:', payload);\n};\n\n// create a event listeners\nevent.on('connecting', listener);\nevent.on('connected', listener, this); // optionally bind context to the listener when invoked\n\n// listen to all events\nevent.on('*', (type, payload) =\u003e {});\n\n// dispatch events\nevent.emit('connected', 'paylod');\n\n// remove a event listener\nconst unsubscribe = event.on('connected', listener);\nunsubscribe();\n\n// remove all listeners for given event\nevent.unbindAll('connected');\n\n// unbind all event listeners\nevent.unbindAll();\n```\n\n### AsyncEvents\n\n```js\nimport { AsyncEvents } from 'capillaries';\n\nconst event = new AsyncEvents();\n\nconst handler = async function (payload) {\n  console.log('Event Received:', payload);\n};\n\n// create a event handler\nevent.on('connected', handler);\n\n// call the event\nawait event.call('connected', 'paylod');\n\n// remove a event listener\nconst unsubscribe = event.on('connected', handler);\nunsubscribe();\n\n// unbind/remove all events\nevent.unbindAll();\n```\n\nOnly one event handler can be attached per event. Attaching more than one event will throw an error.\n\n### Hooks\n\n```js\nimport { Hooks } from 'capillaries';\n\nconst hooks = new Hooks();\n\n// create a tap\nhooks.tap('Hook', () =\u003e {\n  return 'Hello World!';\n});\n\nhooks.tap('AsyncHook', async () =\u003e {\n  return 'Hello World!';\n});\n\n// Call the taps\nhooks.call('Hook', payload); //-\u003e returns undefined\nhooks.callWaterFall('Hook', payload); //-\u003e returns 'Hello World!'\nhooks.callAsync('AsyncHook', payload); // awaits on taps, returns undefined\nhooks.callAsyncWaterFall('AsyncHook', payload); // awaits on taps, returns 'Hello World!'\n\n// remove all hooks\nhooks.clear();\n```\n\nHooks are executed in order. The calling waterfall hook passes a return value from each function to the next function and returns data from the last tap\n\n### Browser compatibility\n\n- Chrome 38+\n- Edge 12+\n- Firefox 13+\n- Opera 25+\n- Safari 8+\n- Internet Explorer 11\n\n[npm]: https://www.npmjs.com/\n[yarn]: https://yarnpkg.com/lang/en/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsibiraj-s%2Fcapillaries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsibiraj-s%2Fcapillaries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsibiraj-s%2Fcapillaries/lists"}