@@ -33,10 +33,8 @@ val client by lazy {
33
33
34
34
@Composable
35
35
fun App () {
36
- var serviceOrNull: UserService ? by remember { mutableStateOf(null ) }
37
-
38
- LaunchedEffect (Unit ) {
39
- serviceOrNull = client.rpc {
36
+ val rpcClient = remember {
37
+ client.rpc {
40
38
url {
41
39
host = DEV_SERVER_HOST
42
40
port = 8080
@@ -48,53 +46,51 @@ fun App() {
48
46
json()
49
47
}
50
48
}
51
- }.withService()
49
+ }
52
50
}
53
51
54
- val service = serviceOrNull // for smart casting
52
+ val service: UserService = remember { rpcClient.withService() }
55
53
56
- if (service != null ) {
57
- var greeting by remember { mutableStateOf<String ?>(null ) }
58
- val news = remember { mutableStateListOf<String >() }
54
+ var greeting by remember { mutableStateOf<String ?>(null ) }
55
+ val news = remember { mutableStateListOf<String >() }
59
56
60
- LaunchedEffect (service) {
61
- greeting = service.hello(
62
- " User from ${getPlatform().name} platform" ,
63
- UserData (" Berlin" , " Smith" )
64
- )
65
- }
57
+ LaunchedEffect (service) {
58
+ greeting = service.hello(
59
+ " User from ${getPlatform().name} platform" ,
60
+ UserData (" Berlin" , " Smith" )
61
+ )
62
+ }
66
63
67
- LaunchedEffect (service) {
68
- service.subscribeToNews().collect { article ->
69
- news.add(article)
70
- }
64
+ LaunchedEffect (service) {
65
+ service.subscribeToNews().collect { article ->
66
+ news.add(article)
71
67
}
68
+ }
72
69
73
- MaterialTheme {
74
- var showIcon by remember { mutableStateOf(false ) }
70
+ MaterialTheme {
71
+ var showIcon by remember { mutableStateOf(false ) }
75
72
76
- Column (Modifier .fillMaxWidth(), horizontalAlignment = Alignment .CenterHorizontally ) {
77
- greeting?.let {
78
- Text (it)
79
- } ? : run {
80
- Text (" Establishing server connection..." )
81
- }
73
+ Column (Modifier .fillMaxWidth(), horizontalAlignment = Alignment .CenterHorizontally ) {
74
+ greeting?.let {
75
+ Text (it)
76
+ } ? : run {
77
+ Text (" Establishing server connection..." )
78
+ }
82
79
83
- news.forEach {
84
- Text (" Article: $it " )
85
- }
80
+ news.forEach {
81
+ Text (" Article: $it " )
82
+ }
86
83
87
- Button (onClick = { showIcon = ! showIcon }) {
88
- Text (" Click me!" )
89
- }
84
+ Button (onClick = { showIcon = ! showIcon }) {
85
+ Text (" Click me!" )
86
+ }
90
87
91
- AnimatedVisibility (showIcon) {
92
- Column (
93
- Modifier .fillMaxWidth(),
94
- horizontalAlignment = Alignment .CenterHorizontally
95
- ) {
96
- Image (painterResource(Res .drawable.compose_multiplatform), null )
97
- }
88
+ AnimatedVisibility (showIcon) {
89
+ Column (
90
+ Modifier .fillMaxWidth(),
91
+ horizontalAlignment = Alignment .CenterHorizontally
92
+ ) {
93
+ Image (painterResource(Res .drawable.compose_multiplatform), null )
98
94
}
99
95
}
100
96
}
0 commit comments