Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Merge requests
!102
Project 'elixxir/elixxir-dapps-sdk-swift' was moved to 'mobile/ios/elixxir-dapps-sdk-swift'. Please update any links and bookmarks that may still have the old path.
Release 1.0.0
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Release 1.0.0
development
into
main
Overview
0
Commits
1078
Pipelines
0
Changes
4
Merged
Dariusz Rybicki
requested to merge
development
into
main
2 years ago
Overview
0
Commits
1078
Pipelines
0
Changes
4
Expand
0
0
Merge request reports
Viewing commit
c438e054
Show latest version
4 files
+
141
−
169
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
c438e054
Migrate RegisterFeature to ReducerProtocol
· c438e054
Dariusz Rybicki
authored
2 years ago
Examples/xx-messenger/Sources/RegisterFeature/RegisterComponent.swift
0 → 100644
+
104
−
0
Options
import
AppCore
import
ComposableArchitecture
import
Foundation
import
XCTestDynamicOverlay
import
XXClient
import
XXMessengerClient
import
XXModels
public
struct
RegisterComponent
:
ReducerProtocol
{
public
struct
State
:
Equatable
{
public
enum
Error
:
Swift
.
Error
,
Equatable
{
case
usernameMismatch
(
registering
:
String
,
registered
:
String
?)
}
public
enum
Field
:
String
,
Hashable
{
case
username
}
public
init
(
focusedField
:
Field
?
=
nil
,
username
:
String
=
""
,
isRegistering
:
Bool
=
false
,
failure
:
String
?
=
nil
)
{
self
.
focusedField
=
focusedField
self
.
username
=
username
self
.
isRegistering
=
isRegistering
self
.
failure
=
failure
}
@BindableState
public
var
focusedField
:
Field
?
@BindableState
public
var
username
:
String
public
var
isRegistering
:
Bool
public
var
failure
:
String
?
}
public
enum
Action
:
Equatable
,
BindableAction
{
case
registerTapped
case
failed
(
String
)
case
finished
case
binding
(
BindingAction
<
State
>
)
}
public
init
()
{}
@Dependency
(\
.
app
.
messenger
)
var
messenger
:
Messenger
@Dependency
(\
.
app
.
dbManager
.
getDB
)
var
db
:
DBManagerGetDB
@Dependency
(\
.
app
.
now
)
var
now
:
()
->
Date
@Dependency
(\
.
app
.
mainQueue
)
var
mainQueue
:
AnySchedulerOf
<
DispatchQueue
>
@Dependency
(\
.
app
.
bgQueue
)
var
bgQueue
:
AnySchedulerOf
<
DispatchQueue
>
public
var
body
:
some
ReducerProtocol
<
State
,
Action
>
{
BindingReducer
()
Reduce
{
state
,
action
in
switch
action
{
case
.
binding
(
_
):
return
.
none
case
.
registerTapped
:
state
.
focusedField
=
nil
state
.
isRegistering
=
true
state
.
failure
=
nil
return
.
future
{
[
username
=
state
.
username
]
fulfill
in
do
{
let
db
=
try
db
()
try
messenger
.
register
(
username
:
username
)
let
contact
=
try
messenger
.
myContact
()
let
facts
=
try
contact
.
getFacts
()
try
db
.
saveContact
(
Contact
(
id
:
try
contact
.
getId
(),
marshaled
:
contact
.
data
,
username
:
facts
.
get
(
.
username
)?
.
value
,
email
:
facts
.
get
(
.
email
)?
.
value
,
phone
:
facts
.
get
(
.
phone
)?
.
value
,
createdAt
:
now
()
))
guard
facts
.
get
(
.
username
)?
.
value
==
username
else
{
throw
State
.
Error
.
usernameMismatch
(
registering
:
username
,
registered
:
facts
.
get
(
.
username
)?
.
value
)
}
fulfill
(
.
success
(
.
finished
))
}
catch
{
fulfill
(
.
success
(
.
failed
(
error
.
localizedDescription
)))
}
}
.
subscribe
(
on
:
bgQueue
)
.
receive
(
on
:
mainQueue
)
.
eraseToEffect
()
case
.
failed
(
let
failure
):
state
.
isRegistering
=
false
state
.
failure
=
failure
return
.
none
case
.
finished
:
state
.
isRegistering
=
false
return
.
none
}
}
}
}
Loading