{"id":19313652,"url":"https://github.com/geektree0101/optical","last_synced_at":"2025-07-27T09:07:33.620Z","repository":{"id":141412735,"uuid":"199351047","full_name":"GeekTree0101/Optical","owner":"GeekTree0101","description":"Lightweight \u0026 Predictable state management framework for iOS","archived":false,"fork":false,"pushed_at":"2019-07-31T01:00:17.000Z","size":686,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T22:42:25.524Z","etag":null,"topics":["architecture","ios","state-management","unidirectional"],"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/GeekTree0101.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-29T00:25:17.000Z","updated_at":"2019-08-30T05:49:35.000Z","dependencies_parsed_at":"2024-01-13T15:37:40.008Z","dependency_job_id":"7cae77fa-a0a6-49ac-83af-418725fff395","html_url":"https://github.com/GeekTree0101/Optical","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GeekTree0101/Optical","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeekTree0101%2FOptical","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeekTree0101%2FOptical/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeekTree0101%2FOptical/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeekTree0101%2FOptical/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GeekTree0101","download_url":"https://codeload.github.com/GeekTree0101/Optical/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GeekTree0101%2FOptical/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267334190,"owners_count":24070521,"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-07-27T02:00:11.917Z","response_time":82,"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":["architecture","ios","state-management","unidirectional"],"created_at":"2024-11-10T00:40:36.009Z","updated_at":"2025-07-27T09:07:33.567Z","avatar_url":"https://github.com/GeekTree0101.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/GeekTree0101/Optical/blob/master/screenshots/banner.png\" /\u003e\n\n[![CI Status](https://img.shields.io/travis/Geektree0101/Optical.svg?style=flat)](https://travis-ci.org/Geektree0101/Optical)\n[![Version](https://img.shields.io/cocoapods/v/Optical.svg?style=flat)](https://cocoapods.org/pods/Optical)\n[![License](https://img.shields.io/cocoapods/l/Optical.svg?style=flat)](https://cocoapods.org/pods/Optical)\n[![Platform](https://img.shields.io/cocoapods/p/Optical.svg?style=flat)](https://cocoapods.org/pods/Optical)\n\n## Intro\nOptical is a lightweight and predictable state management pattern framework for iOS\n\n\u003cimg src=\"https://github.com/GeekTree0101/Optical/blob/master/screenshots/intro1.png\" /\u003e\n\n- [X] Find and fix bugs faster and easier.\n- [X] Change existing behaviors with confidence.\n- [X] Add new features easily.\n- [X] **Write shorter** methods with single responsibility.\n- [X] Extract business logic from view controllers into **opticle**.\n- [X] Build **reusable** components with network services and utilities objects.\n- [X] Write factored code from the start.\n- [X] Write fast and **maintainable unit tests** with state base.\n- [X] Have **confidence in your tests** to catch regression.\n\n## Structures\n\n### Workflow\n\n\u003cimg src=\"https://github.com/GeekTree0101/Optical/blob/master/screenshots/intro2.png\" /\u003e\n\n- Dispatch: You can request network(backend) service or API and commit response for mutating state\n```swift\n  var service: NetworkService = .init()\n\n  func dispatch(_ request: Request) {\n    // do commit\n    service.request(onSuccess: { [weak self] response in\n      self?.commit(.success(response))\n    })\n  }\n```\n- Mutation: You can mutate currentState with utilities base on **previous state with response** from dispatcher\n```swift\n  var utility: SomeUtil = .init()\n\n  func mutate(_ state: State, response: Response) {\n    var newState = state\n    newState.value = utility.makeValue(from: response)\n    return newState\n  }\n```\n- Watcher: You can **observe state**  changing from opticle\n```swift\nlet opticle = SomeOpticle()\n\nopticle.watch.live { newState in \n  print(newSate.value)\n}\n\n// you can observe state duplicately!\nopticle.watch.live({ newState in \n  print(\"listen one more \\(newSate.value)\")\n})\n\n// you can observe state on other dispatch qos!\nopticle.watch.live(on: DispatchQueue.global(.background), { newState in \n  print(\"background \\(newSate.value)\")\n})\n\n// Map \u0026 Fillter \nopticle.watch.map { $0.list }.filter { $0.count \u003e 10 }.live({ list in \n  print(\"map \u0026 filter\")\n})\n```\n\n### Mutation \u0026 Recover\n\n\u003cimg src=\"https://github.com/GeekTree0101/Optical/blob/master/screenshots/intro3.png\" /\u003e\n\n- Mutation: It will be called by success commit from dispatcher\n- Recover: You can recover state base on error. it will be called by error commit from dispatcher\n\n```swift\n  func dispatch(_ request: Request) {\n    // success\n    self.commit(.success)\n    \n    // error\n    self.commit(.failed(error), from: request)\n  }\n  \n  func mutate(_ state: State, response: Response) -\u003e State {\n    // .success only\n  }\n  \n  func recover(_ state: State, request: Request, error: Error?) -\u003e State {\n    // .failed from request\n  }\n```\n\n## Installation\n\nOptical is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'Optical'\n```\n\n## Author\n\nGeektree0101, h2s1880@gmail.com\n\n## License\n\nOptical is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeektree0101%2Foptical","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeektree0101%2Foptical","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeektree0101%2Foptical/lists"}