{"id":16853167,"url":"https://github.com/devxoul/alertreactor","last_synced_at":"2025-09-04T12:33:38.707Z","repository":{"id":56901882,"uuid":"98679986","full_name":"devxoul/AlertReactor","owner":"devxoul","description":"A ReactorKit extension for UIAlertController","archived":false,"fork":false,"pushed_at":"2019-06-15T06:10:10.000Z","size":35,"stargazers_count":24,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T00:50:02.019Z","etag":null,"topics":["reactorkit","uialertcontroller"],"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/devxoul.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":"2017-07-28T19:09:19.000Z","updated_at":"2025-02-23T08:37:41.000Z","dependencies_parsed_at":"2022-08-21T02:50:55.811Z","dependency_job_id":null,"html_url":"https://github.com/devxoul/AlertReactor","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/devxoul/AlertReactor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FAlertReactor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FAlertReactor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FAlertReactor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FAlertReactor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devxoul","download_url":"https://codeload.github.com/devxoul/AlertReactor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FAlertReactor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273609541,"owners_count":25136595,"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-09-04T02:00:08.968Z","response_time":61,"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":["reactorkit","uialertcontroller"],"created_at":"2024-10-13T13:50:00.097Z","updated_at":"2025-09-04T12:33:38.660Z","avatar_url":"https://github.com/devxoul.png","language":"Swift","readme":"# AlertReactor\n\n![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg)\n[![CocoaPods](http://img.shields.io/cocoapods/v/AlertReactor.svg)](https://cocoapods.org/pods/AlertReactor)\n[![Build Status](https://travis-ci.org/devxoul/AlertReactor.svg?branch=master)](https://travis-ci.org/devxoul/AlertReactor)\n[![Codecov](https://img.shields.io/codecov/c/github/devxoul/AlertReactor.svg)](https://codecov.io/gh/devxoul/AlertReactor)\n\nAlertReactor is a ReactorKit extension for UIAlertController. It provides an elegant way to deal with an UIAlertController. Best fits if you have lazy-loaded alert actions.\n\n![alertreactor](https://user-images.githubusercontent.com/931655/28745788-ab587fbe-74ba-11e7-9c41-d3dfac34f255.png)\n\n## Features\n\n* ✏️ Statically typed alert actions\n* 🕹 Reactive and dynamic action bindings\n\n## At a Glance\n\nThis is an example implementation of an `AlertReactor`:\n\n```swift\nfinal class UserAlertReactor: AlertReactor\u003cUserAlertAction\u003e {\n  override func mutate(action: Action) -\u003e Observable\u003cMutation\u003e {\n    switch action {\n    case .prepare:\n      return .just(.setActions([.copy, .follow, .block, .cancel]))\n\n    case let .selectAction(alertAction):\n      switch alertAction {\n      case .copy: return foo()\n      case .follow: return foo()\n      case .unfollow: return foo()\n      case .block: return foo()\n      case .cancel: return foo()\n      }\n    }\n  }\n}\n```\n\n## Getting Started\n\n### 1. Defining an Alert Action\n\nFirst you should define a new type which conforms to a protocol `AlertActionType`. This is an abstraction model of `UIAlertAction`. This protocol requires a `title`(required), `style`(optional) and `isEnabled`(optional) property.\n\n```swift\nenum UserAlertAction: AlertActionType {\n  case loading\n  case follow\n  case block\n  case cancel\n\n  // required\n  var title: String {\n    switch self {\n    case .loading: return \"Loading\"\n    case .follow: return \"Follow\"\n    case .block: return \"Block\"\n    case .cancel: return \"Cancel\"\n    }\n  }\n\n  // optional\n  var style: UIAlertActionStyle {\n    switch self {\n    case .loading: return .default\n    case .follow: return .default\n    case .block: return .destructive\n    case .cancel: return .cancel\n    }\n  }\n\n  // optional\n  var isEnabled: Bool {\n    switch self {\n    case .loading: return false\n    default: return true\n    }\n  }\n}\n```\n\n\n### 2. Creating an Alert Reactor\n\n`AlertReactor` is a generic reactor class. It takes a single generic type which conforms to a protocol `AlertActionType`. This reactor provides a default action, mutation and a state. Here is a simplified definition of `AlertReactor`. You may subclass this class and override `mutate(action:)` method to implement specific business logic.\n\n```swift\nclass AlertReactor\u003cAlertAction: AlertActionType\u003e: Reactor {\n  enum Action {\n    case prepare // on viewDidLoad()\n    case selectAction(AlertAction) // on select action\n  }\n\n  enum Mutation {\n    case setTitle(String?)\n    case setMessage(String?)\n    case setActions([AlertAction])\n  }\n\n  struct State {\n    public var title: String?\n    public var message: String?\n    public var actions: [AlertAction]\n  }\n}\n```\n\nWe're gonna use the `UserAlertAction` as a generic parameter to create a new subclass of `AlertReactor`.\n\n```swift\nfinal class UserAlertReactor: AlertReactor\u003cUserAlertAction\u003e {\n  override func mutate(action: Action) -\u003e Observable\u003cMutation\u003e {\n    switch action {\n    case .prepare:\n      return .just(Mutation.setActions([.copy, .follow, .block, .cancel]))\n\n    case let .selectAction(alertAction):\n      switch alertAction {\n      case .loading: return .empty()\n      case .follow: return UserAPI.follow()\n      case .block: return UserAPI.block()\n      case .cancel: return .empty()\n      }\n    }\n  }\n}\n```\n\n### 3. Presenting an Alert Controller\n\n`AlertController` is a subclass of `UIAlertController` which conforms to a protocol `View` from ReactorKit. This class also takes a single generic type of `AlertActionType`. You can initialize this class with some optional parameters: `reactor` and `preferredStyle`. Just present it then the reactor will handle the business logic for you.\n\n```swift\nlet reactor = UserAlertReactor()\nlet controller = AlertController\u003cUserAlertAction\u003e(reactor: reactor, preferredStyle: .actionSheet)\nself.present(controller, animated: true, completion: nil)\n```\n\n## Installation\n\n```ruby\npod 'AlertReactor'\n```\n\n## License\n\nAlertReactor is under MIT license. See the [LICENSE](LICENSE) for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2Falertreactor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevxoul%2Falertreactor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2Falertreactor/lists"}