{"id":32109949,"url":"https://github.com/gujci/eventemitter","last_synced_at":"2025-10-20T13:47:39.260Z","repository":{"id":64060011,"uuid":"52799213","full_name":"Gujci/EventEmitter","owner":"Gujci","description":"a lightweight tool to easily implement listener pattern","archived":false,"fork":false,"pushed_at":"2020-05-25T10:34:53.000Z","size":74,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-20T13:47:38.679Z","etag":null,"topics":["carthage","eventemitter","listener-pattern","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/Gujci.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":"2016-02-29T14:52:24.000Z","updated_at":"2021-10-12T16:47:01.000Z","dependencies_parsed_at":"2022-12-01T20:09:57.471Z","dependency_job_id":null,"html_url":"https://github.com/Gujci/EventEmitter","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/Gujci/EventEmitter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gujci%2FEventEmitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gujci%2FEventEmitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gujci%2FEventEmitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gujci%2FEventEmitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gujci","download_url":"https://codeload.github.com/Gujci/EventEmitter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gujci%2FEventEmitter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280102711,"owners_count":26272390,"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","status":"online","status_checked_at":"2025-10-20T02:00:06.978Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["carthage","eventemitter","listener-pattern","swift"],"created_at":"2025-10-20T13:47:35.952Z","updated_at":"2025-10-20T13:47:39.256Z","avatar_url":"https://github.com/Gujci.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EventEmitter\nA lightweight tool to easily implement listener pattern.\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Build Status](https://travis-ci.org/Gujci/EventEmitter.svg?branch=master)](https://travis-ci.org/Gujci/EventEmitter)\n![Swift](https://github.com/Gujci/EventEmitter/workflows/Swift/badge.svg)\n\nExample\n========\n\nSubscribe to events w parameters:\n```swift\neventEmitterInstance.on(\"eventWithParameter\") { (weak parameter: Any?) in\n    //...\n}\n```\nOr w/o parameters:\n```swift\neventEmitterInstance.on(\"eventWithoutParameter\") {\n    //...\n}\n```\n\nDefining events with an enum is also supported:\n```swift\npublic enum AppEvent: String, Event {\n    case some\n    case other\n}\n```\n\n```swift\neventEmitterInstance.on(AppEvent.some) {\n    //...\n}\n```\n\nEmit an event with an EventEmitter class\n```swift\nclass EventEmitterClass: EventEmitter {\n  var listeners: Dictionary\u003cString, Array\u003cAny\u003e\u003e? = [:]\n  \n  //...\n  public func foo(parameter: Any?) {\n    //...\n    emit(AppEvent.some, information: parameter)\n  }\n  \n  public func bar() {\n    //...\n    emit(AppEvent.some)\n  }\n}\n```\nNote: This is a protocoll so you can use it with `struct`s as well. \n\n`String` comforms to `Event` protocol, so this is also a valid code:\n\n```swift\nemit(\"some\", information: parameter)\n```\n\n# Documentation\n\n### Functions to be called from an EventEmitter instance\n\n```swift\nemit(_ event: Event)\n```\n\n```swift\nemit\u003cT\u003e(_ event: Event, information: T)\n```\n\n```swift\nemit(onMain event: Event)\n```\n\n```swift\nemit\u003cT\u003e(onMain event: Event, information: T)\n```\n\n\n### Functions to call on an EventEmitter instance\n#### subscribe\n\n```swift\non(_ event: Event, action: (() -\u003e ()))\n```\n\n```swift\non(_ events: [Event], action: (() -\u003e ()))\n```\n\n```swift\nonce(_ event: Event, action: (() -\u003e ()))\n```\n\n```swift\non\u003cT\u003e(_ event: Event, action: ((T?) -\u003e ()))\n```\n\n```swift\non\u003cT\u003e(_ events: [Event], action: ((T?) -\u003e ()))\n```\n\n```swift\nonce\u003cT\u003e(_ event: Event, action: ((T?) -\u003e ()))\n```\n\n#### unsubscribe\n\n```swift\nremoveListeners(_ event: Event?)\n```\n\n# Installation\n\n## SPM \n\nUse the GitHub link in Xcode\n\n## Carthage \n\nPut this line into your cartfile\n\n```\ngithub \"Gujci/EventEmitter\"\n```\n\n### Swift 3\n\nfor Swift 3 use the `0.5.5` tag. This version will not be supported.\n\n```\ngithub \"Gujci/EventEmitter\" \"== 0.5.5\"\n```\n\n# Debugging\n\nTo turn on logging add `EventLoggingEnabled` to 'Arguments passed on launch' at Schema/Run/Arguments\n\n# TODO\n - [x] Travis support\n - [ ] Full code coverage\n - [ ] Support custom threads\n - [x] Once\n - [ ] More documentation\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgujci%2Feventemitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgujci%2Feventemitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgujci%2Feventemitter/lists"}