{"id":13396536,"url":"https://github.com/aleclarson/emitter-kit","last_synced_at":"2025-04-04T07:08:21.675Z","repository":{"id":19261782,"uuid":"22497787","full_name":"aleclarson/emitter-kit","owner":"aleclarson","description":"Type-safe event handling for Swift","archived":false,"fork":false,"pushed_at":"2022-10-14T08:30:53.000Z","size":339,"stargazers_count":566,"open_issues_count":6,"forks_count":70,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-10-20T12:25:47.687Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/aleclarson.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":"2014-08-01T06:25:36.000Z","updated_at":"2024-09-10T17:04:17.000Z","dependencies_parsed_at":"2022-08-05T03:00:46.363Z","dependency_job_id":null,"html_url":"https://github.com/aleclarson/emitter-kit","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Femitter-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Femitter-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Femitter-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Femitter-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleclarson","download_url":"https://codeload.github.com/aleclarson/emitter-kit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135144,"owners_count":20889421,"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-07-30T18:00:56.349Z","updated_at":"2025-04-04T07:08:21.651Z","avatar_url":"https://github.com/aleclarson.png","language":"Swift","funding_links":[],"categories":["Events","Libs","Events [🔝](#readme)","Swift","Architecture and State"],"sub_categories":["Events"],"readme":"\n# emitter-kit v5.2.2\n\n![stable](https://img.shields.io/badge/stability-stable-4EBA0F.svg?style=flat)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/EmitterKit.svg?style=flat)](https://cocoapods.org/pods/EmitterKit)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Platform](https://img.shields.io/cocoapods/p/EmitterKit.svg?style=flat)](http://cocoadocs.org/docsets/EmitterKit)\n\nA replacement for `NSNotificationCenter#addObserver` and `NSObject#addObserver` that is **type-safe** and **not verbose**.\n\n```swift\nimport EmitterKit\n\n// A generic event emitter (but type-safe)!\nvar event = Event\u003cT\u003e()\n\n// Any emitted data must be the correct type.\nevent.emit(data)\n\n// This listener will only be called once.\n// You are *not* required to retain it.\nevent.once { data: T in\n  print(data)\n}\n\n// This listener won't stop listening;\n// unless you stop it manually,\n// or its Event\u003cT\u003e is deallocated.\n// You *are* required to retain it.\nvar listener = event.on { data: T in\n  print(data)\n}\n\n// Stop the listener manually.\nlistener.isListening = false\n\n// Restart the listener (if it was stopped).\nlistener.isListening = true\n```\n\n\u0026nbsp;\n\n### Targeting\n\nA **target** allows you to associate a specific `AnyObject` with an `emit` call. This is useful when emitting events associated with classes you can't add properties to (like `UIView`).\n\nWhen calling `emit` with a target, you must also call `on` or `once` with the same target in order to receive the emitted event.\n\n```Swift\nlet myView = UIView()\nlet didTouch = Event\u003cUITouch\u003e()\n\ndidTouch.once(myView) { touch in\n  print(touch)\n}\n\ndidTouch.emit(myView, touch)\n```\n\n\u0026nbsp;\n\n### NSNotification\n\nThe `Notifier` class helps when you are forced to use `NSNotificationCenter` (for example, if you want to know when the keyboard has appeared).\n\n```swift\n// You are **not** required to retain this after creating your listener.\nvar event = Notifier(UIKeyboardWillShowNotification)\n\n// Handle NSNotifications with style!\nlistener = event.on { (notif: Notification) in\n  print(notif.userInfo)\n}\n```\n\n\u0026nbsp;\n\n### Key-Value Observation (KVO)\n\n```swift\n// Any NSObject descendant will work.\nvar view = UIView()\n\n// \"Make KVO great again!\" - Donald Trump\nlistener = view.on(\"bounds\") { (change: Change\u003cCGRect\u003e) in\n  print(change)\n}\n```\n\n\u0026nbsp;\n\n### Thread Safety\n\n⚠️ None of the classes in EmitterKit are thread-safe!\n\nThe following actions must be done on the same thread, or you need manual locking:\n- Emit an event\n- Add/remove a listener\n- Set the `isListening` property of a listener\n\n\u0026nbsp;\n\n### v5.2.2 changelog\n\n- Fixed protocol casting (#60)\n\n### v5.2.1 changelog\n\n- Fix Carthage compatibility for non iOS platforms\n\n### v5.2.0 changelog\n\n- Added the `Event.getListeners` method\n- Listeners are now always called in the order they were added\n- Event\u003cVoid\u003e.emit() can be called without an argument\n- Carthage support has been improved\n\n### v5.1.0 changelog\n\n- The `NotificationListener` class now takes a `Notification` instead of an `NSDictionary`.\n\n- A `NotificationListener` without a target will now receive every `Notification` with its name, regardless of the value of `notif.object`.\n\n### v5.0.0 changelog\n\n- Swift 3.0 + Xcode 8.0 beta 6 support\n\n- The `Signal` class was removed. (use `Event\u003cVoid\u003e` instead)\n\n- The `Emitter` abstract class was removed.\n\n- The `EmitterListener` class was renamed `EventListener\u003cT\u003e`.\n\n- The `Event\u003cT\u003e` class no longer has a superclass.\n\n- The `Notification` class was renamed `Notifier` (to prevent collision with `Foundation.Notification`).\n\n- The `on` and `once` methods of `Event\u003cT\u003e` now return an `EventListener\u003cT\u003e` (instead of just a `Listener`)\n\n- The `on` and `once` methods of `Notifier` now return an `NotificationListener` (instead of just a `Listener`)\n\n- The `on` and `once` methods of `NSObject` now return an `ChangeListener\u003cT\u003e` (instead of just a `Listener`)\n\n- The `keyPath`, `options`, and `object` properties of `ChangeListener\u003cT\u003e` are now public.\n\n- A `listenerCount: Int` computed property was added to the `Event\u003cT\u003e` class.\n\n- An `event: Event\u003cT\u003e` property was added to the `EventListener\u003cT\u003e` class.\n\nThe changelog for older versions can be [found here](https://github.com/aleclarson/emitter-kit/wiki/Changelog).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Femitter-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleclarson%2Femitter-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Femitter-kit/lists"}