@@ -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 rpcClient = remember {
37+ client.rpc {
4038 url {
4139 host = DEV_SERVER_HOST
4240 port = 8080
@@ -48,53 +46,51 @@ fun App() {
4846 json()
4947 }
5048 }
51- }.withService()
49+ }
5250 }
5351
54- val service = serviceOrNull // for smart casting
52+ val service: UserService = remember { rpcClient.withService() }
5553
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 >() }
5956
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+ }
6663
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)
7167 }
68+ }
7269
73- MaterialTheme {
74- var showIcon by remember { mutableStateOf(false ) }
70+ MaterialTheme {
71+ var showIcon by remember { mutableStateOf(false ) }
7572
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+ }
8279
83- news.forEach {
84- Text (" Article: $it " )
85- }
80+ news.forEach {
81+ Text (" Article: $it " )
82+ }
8683
87- Button (onClick = { showIcon = ! showIcon }) {
88- Text (" Click me!" )
89- }
84+ Button (onClick = { showIcon = ! showIcon }) {
85+ Text (" Click me!" )
86+ }
9087
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 )
9894 }
9995 }
10096 }
0 commit comments