Skip to content

Instantly share code, notes, and snippets.

@KhayalSuleymani
Last active October 19, 2024 08:52
Show Gist options
  • Save KhayalSuleymani/a32ca1c7cfaf9c8825f96a81f8e671d4 to your computer and use it in GitHub Desktop.
Save KhayalSuleymani/a32ca1c7cfaf9c8825f96a81f8e671d4 to your computer and use it in GitHub Desktop.
mvvm
import Common
class PasscodeViewModel: ViewModel<PasscodeViewItem> {
@discardableResult
override func move(by c: C<AuthorizeRoute>) -> Self {
onSelect(weaks { this, event in
switch event {
case let .passcode(state):
switch state {
case let .set(passcode):
c.move(to: .passcode(.again(passcode)))
case let .again(passcode):
this.service.s1.request(.init(passcode: passcode)) { result in
switch result {
case .success:
c.move(.dashboard(.set(passcode)))
case let .failure(e):
this.render(state: .error(e, nil))
}
}
case _:
break
}
case _:
scanf(self)
}
})
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment