{"id":22015899,"url":"https://github.com/pircate/rxswiftdemo","last_synced_at":"2025-05-07T01:08:40.964Z","repository":{"id":119020816,"uuid":"133928706","full_name":"Pircate/RxSwiftDemo","owner":"Pircate","description":"RxSwift Demo","archived":false,"fork":false,"pushed_at":"2021-09-02T02:23:06.000Z","size":7949,"stargazers_count":21,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T04:51:11.160Z","etag":null,"topics":["mvvm","rxswift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pircate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-18T08:50:39.000Z","updated_at":"2022-11-19T21:59:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"54f6dea6-0902-4b10-abac-88221206c817","html_url":"https://github.com/Pircate/RxSwiftDemo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxSwiftDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxSwiftDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxSwiftDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FRxSwiftDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pircate","download_url":"https://codeload.github.com/Pircate/RxSwiftDemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252793647,"owners_count":21805057,"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":["mvvm","rxswift"],"created_at":"2024-11-30T04:29:54.479Z","updated_at":"2025-05-07T01:08:40.952Z","avatar_url":"https://github.com/Pircate.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LightCloud\nRxSwift 登录/注册/搜索/编辑/网络 Demo\n\n## ViewModel\n```swift\nfinal class LoginViewModel {\n    \n    struct Input {\n        let username: Observable\u003cString\u003e\n        let password: Observable\u003cString\u003e\n        let captchaTap: ControlEvent\u003cVoid\u003e\n        let loginTap: ControlEvent\u003cVoid\u003e\n    }\n    \n    struct Output {\n        let isEnabled: Driver\u003cBool\u003e\n        let captcha: Driver\u003c(title: String, isEnabled: Bool)\u003e\n        let login: Driver\u003cBool\u003e\n        let state: Driver\u003cUIState\u003e\n    }\n}\n\nextension LoginViewModel: ViewModelType {\n    \n    func transform(_ input: LoginViewModel.Input) -\u003e LoginViewModel.Output {\n        let isEnabled = input.verifyloginButton()\n        \n        let state = State()\n        let captcha = input.requestLoginCaptcha(state)\n        let login = input.requestLogin(state)\n        \n        return Output(isEnabled: isEnabled,\n                      captcha: captcha,\n                      login: login,\n                      state: state.asDriver(onErrorJustReturn: .idle))\n    }\n}\n\nfileprivate extension LoginViewModel.Input {\n    \n    func verifyloginButton() -\u003e Driver\u003cBool\u003e {\n        return Observable\n        \t.combineLatest(username.isEmpty, password.isEmpty) { !$0 \u0026\u0026 !$1 }\n            .asDriver(onErrorJustReturn: false)\n    }\n    \n    func requestLoginCaptcha(_ state: State) -\u003e Driver\u003c(title: String, isEnabled: Bool)\u003e {\n        return captchaTap.withLatestFrom(username)\n            .flatMap{\n                LCUser.rx.requestLoginCaptcha(mobile: $0)\n                    .trackState(state, success: \"验证码已发送\")\n                    .catchErrorJustComplete()\n            }\n            .flatMap(to: 60.countdown())\n            .asDriver(onErrorJustReturn: (title: \"重新发送\", isEnabled: true))\n    }\n    \n    func requestLogin(_ state: State) -\u003e Driver\u003cBool\u003e {\n        let usernameAndPassword = Observable\n        .combineLatest(username, password) { (username: $0, password: $1) }\n        return loginTap.withLatestFrom(usernameAndPassword)\n            .flatMap {\n                LCUser.rx.login(mobile: $0.username, captcha: $0.password)\n                    .trackState(state, success: \"登录成功\")\n                    .catchErrorJustComplete()\n            }\n            .map(to: true)\n            .asDriver(onErrorJustReturn: false)\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpircate%2Frxswiftdemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpircate%2Frxswiftdemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpircate%2Frxswiftdemo/lists"}