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