{"id":15673193,"url":"https://github.com/tuchk4/base-events","last_synced_at":"2025-05-06T22:24:39.412Z","repository":{"id":74717815,"uuid":"49939582","full_name":"tuchk4/base-events","owner":"tuchk4","description":"base-events package. Provides easy way to subscribe and emit events. Super light component","archived":false,"fork":false,"pushed_at":"2017-07-24T10:00:28.000Z","size":5,"stargazers_count":15,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-26T11:37:59.602Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/tuchk4.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}},"created_at":"2016-01-19T08:56:45.000Z","updated_at":"2021-08-19T15:10:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"0b1a37f7-75d3-41a7-a2b8-e97bc769c742","html_url":"https://github.com/tuchk4/base-events","commit_stats":null,"previous_names":["frankland/base-events"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Fbase-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Fbase-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Fbase-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuchk4%2Fbase-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuchk4","download_url":"https://codeload.github.com/tuchk4/base-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252777741,"owners_count":21802645,"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-10-03T15:38:20.596Z","updated_at":"2025-05-06T22:24:39.362Z","avatar_url":"https://github.com/tuchk4.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Base events\n\nProvides easy way to subscribe and emit events. Super light component\n\n`npm install --save base-events`\n \n### How to use\n\n```js\nimport BaseEvents from 'base-events';\n\nconst events = new BaseEvents();\n\nevents.on('a.b.c', () =\u003e {\n  console.log('a.b.c fired');\n});\n\nevents.once('x.y.z', () =\u003e {\n  console.log('x.y.z fired');\n});\n\nevents.emit('a.b.c');\nevents.emit('x.y.z');\n\nevents.emit('x.y.z'); // will not emit x.y.z for second time\n\n\nconst off = events.on('a', () =\u003e {\n  // ....\n});\n\noff(); // unsubscribe listener\n```\n\n### Extends\n\n```js\nimport BaseEvents from 'base-events';\n\nclass Manager extends BaseEvents {\n  constructor() {\n    super();\n  }\n  \n  add(component) {\n    // ...\n    this.emit('component.add', {\n      component\n    });\n  }\n}\n\nconst manager = new Manager();\n\nmanager.on('component.add', ({ component }) =\u003e { \n // ....\n});\n```\n\n### Available methods\n\n- `on(event, callback)` - subscribe for event. Returns **unsubscribe** function\n- `once(event, callback)` - subscribe for event. Will be emitted only one time\n- `emit(event, arguments)` - trigger event with provided arguments\n\n\n### Community\nYou are always welcome for ideas and pull requests :)\n\n\n### TODO\n\n- [ ] Event keys as patterns. If you are interested in this - please comment here https://github.com/tuchk4/base-events/issues/1\n\n```js\nconst events = new BaseEvents();\n\nevents.on('a', () =\u003e { ... });\nevents.on('a.*', () =\u003e { ... });\nevents.on('a.b.c', () =\u003e { ... });\nevents.on('a.*.c', () =\u003e { ... });\n\n\nevents.emit('a', params); // available listeners: a\nevents.emit('a.b.c', params); // available listeners: a.* / a.b.c / a.*.c\nevents.emit('a.B.c', params); // available listeners: a.*.c\n\nevents.emit('x.y.z', params); // no listeners\nevents.emit('a', params);  // available listeners: a\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuchk4%2Fbase-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuchk4%2Fbase-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuchk4%2Fbase-events/lists"}