{"id":18268387,"url":"https://github.com/bionelabs/reflectly","last_synced_at":"2025-04-09T02:46:53.421Z","repository":{"id":62452734,"uuid":"263837283","full_name":"bionelabs/Reflectly","owner":"bionelabs","description":"I learn how to make a reactive function, variable, and custom UI with closure for action. And I don't want to use \"disposableBag\". So I make this library from 2015. I have known my library not good. But I learn a lot about reactive programming.","archived":false,"fork":false,"pushed_at":"2023-04-11T03:05:45.000Z","size":111,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T22:16:40.340Z","etag":null,"topics":["debounce","filter","flatmap","map","operator","reactive","reactive-programming","swift","throttle"],"latest_commit_sha":null,"homepage":"https://onebuffer.com","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/bionelabs.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}},"created_at":"2020-05-14T06:46:13.000Z","updated_at":"2023-07-10T01:12:10.000Z","dependencies_parsed_at":"2023-07-14T07:15:29.216Z","dependency_job_id":null,"html_url":"https://github.com/bionelabs/Reflectly","commit_stats":null,"previous_names":["bionelabs/reflectly","onebuffer/reflectly"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bionelabs%2FReflectly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bionelabs%2FReflectly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bionelabs%2FReflectly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bionelabs%2FReflectly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bionelabs","download_url":"https://codeload.github.com/bionelabs/Reflectly/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247968240,"owners_count":21025797,"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":["debounce","filter","flatmap","map","operator","reactive","reactive-programming","swift","throttle"],"created_at":"2024-11-05T11:31:17.455Z","updated_at":"2025-04-09T02:46:53.404Z","avatar_url":"https://github.com/bionelabs.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ccenter\u003e\u003cimg src=\"https://github.com/onebuffer/Reflectly/blob/master/Resources/Reflectly.png\" width=\"60%\"\u003e\u003c/center\u003e\n\n# Swift Reflectly\n\nI learn how to make a reactive function, variable, and custom UI with closure for action.\nAnd I don't want to use \u003cb\u003e\"disposableBag\"\u003c/b\u003e.\nSo I make this library from \u003cb\u003e2015\u003c/b\u003e.\nI have known my library not good. But I learn a lot about reactive programming.\n\n## Reactive\n1. \u003cb\u003ePromise\u003c/b\u003e: Function response in queue with operators\n2. \u003cb\u003eVariable\u003c/b\u003e: Variable reactive when it changed \n3. \u003cb\u003eUI Reactive\u003c/b\u003e: Button, Switch, Custome by Promise\n4. \u003cb\u003eObject Cache Reactive (Store, Pool)\u003c/b\u003e: Cache object from request and make reactive change to update UI\n5. \u003cb\u003ePromise Await\u003c/b\u003e: wait multi response of Promise function\n\n## Operators\n- [x] throttle\n- [x] debounce\n- [x] filter\n- [x] distinct\n- [x] map\n- [ ] flatMap\n\n## UIView\n- [x] Button\n- [x] Switch\n- [ ] TextField\n- [ ] TextView\n- [ ] View Guesture\n- [ ] View Constraint\n- [ ] View properties\n- [ ] ...\n\n## Issues\n- [ ] promise.resolve() \n\n## Promise\n\n```swift\n        let promies: Promise\u003cString?\u003e = Promise\u003cString?\u003e()\n        promies\n            .map { $0 }\n            .throttle(interval: 500)\n            .debounce(interval: 200)\n            .filter { ($0?.contains(\"3\") ?? false) }\n            .distinct()\n            .observe { (result) in\n                guard case let .success(vax) = result else { return }\n                print(\"result success:\", vax)\n        }\n        \n        promies.resolve(nil)\n        promies.resolve(\"334\")\n        promies.resolve(\"22\")\n        promies.resolve(\"44\")\n        promies.resolve(\"32\")\n```\n\n## Make a promise function\n\n```swift\n    func add(a: Int, b: Int) -\u003e Future\u003cInt\u003e {\n        let promise = Promise\u003cInt\u003e()\n        promise.resolve(a + b)\n        return promise\n    }\n\n```\n\n## Await\n\n```swift\n\n        do {\n            let add1: Int = try await { self.add(a: 8, b: 9) }\n            print(\"ober1:\", add1)\n            let add2: Int = try await { self.add(a: 5, b: 15) }\n            print(\"ober2:\", add2)\n            print(\"add1 + add2:\", add1 + add2)\n        } catch let error {\n            print(\"error:\", error)\n        }\n        \n        // Result:\n        // ober1: 17\n        // ober2: 20\n        // add1 + add2: 37\n\n```\n\n\n## Variable\n\n```swift\n\nlet variable: Variable\u003cInt\u003e = Variable\u003cInt\u003e(0)\n        \n        variable\n            .map { $0 + 1212 }\n            .throttle(interval: 500)\n            .debounce(interval: 200)\n            .filter {$0 \u003e 10}\n            .observe { (result) in\n                guard case let .success(vax) = result else { return }\n                print(\"result success:\", vax)\n        }\n        \n        \n        DispatchQueue.global(qos: .background).async {\n            variable.value = 7\n            usleep(100 * 1000)\n            variable.value = 2\n            usleep(100 * 1000)\n            variable.value = 3\n            usleep(100 * 1000)\n            variable.value = 4\n            usleep(300 * 1000) // waiting a bit longer than the interval\n            variable.value = 5\n            usleep(100 * 1000)\n            variable.value = 6\n            usleep(100 * 1000)\n            variable.value = 7\n            usleep(300 * 1000) // waiting a bit longer than the interval\n            variable.value = 8\n            usleep(100 * 1000)\n            variable.value = 9\n            usleep(100 * 1000)\n            variable.value = 10\n            usleep(100 * 1000)\n            variable.value = 11\n            usleep(100 * 1000)\n            variable.value = 12\n        }\n\n```\n\n## UI Reactive\n\n```swift\n\nclass ViewController: UIViewController {\n    \n    let button: Button = {\n       let button = Button()\n        button.frame = CGRect(x: 100, y: 100, width: 100, height: 50)\n        button.setTitle(\"A\", for: .normal)\n        button.backgroundColor = .red\n        return button\n    }()\n    \n    override func loadView() {\n        super.loadView()\n        self.view.backgroundColor = .white\n        self.view.addSubview(button)\n        \n        button\n        .action()\n        .debounce(interval: 200)\n        .observe { [weak self] (event) in\n            guard let `self` = self else { return}\n            let vc = AViewController()\n            vc.variable = self.variable\n            self.navigationController?.pushViewController(vc, animated: true)\n        }\n    }\n}\n\n```\n\n### Reference\n1. [map, flatMap and compactMap](https://www.hackingwithswift.com/articles/205/whats-the-difference-between-map-flatmap-and-compactmap)\n2. [Under the hood of Futures and Promises in Swift](https://www.swiftbysundell.com/articles/under-the-hood-of-futures-and-promises-in-swift/)\n3. [Promises by Google](https://github.com/google/promises/blob/master/g3doc/index.md#creating-promises)\n4. [RxSwift](https://github.com/ReactiveX/RxSwift/)\n5. [Promise Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\n\n\n## Contact\n- Email: caophuocthanh@gmail.com\n- Site: https://onebuffer.com\n- Linkedin: https://www.linkedin.com/in/caophuocthanh/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbionelabs%2Freflectly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbionelabs%2Freflectly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbionelabs%2Freflectly/lists"}