Tristan Caron
10/11/2019, 3:01 PMval (text, setText) = +state { "Hello, World!" }
And not
var text by State("Hello, World!")
Same questions for @Composable
actually
@Composable
fun MyComponent() {}
Instead of
fun MyComponent = composable { }
Maybe I should wait for an article about this?Fudge
10/11/2019, 3:12 PM@Composable fun x() = Text(“hello”)
becomes
fun x() = composable {
Text(“hello”)
}
)Tristan Caron
10/11/2019, 3:20 PMFudge
10/11/2019, 3:30 PMComposer.x() = composable{}
Luca Nicoletti
10/11/2019, 4:02 PMfun MyComponent() = composable { }
to work 😧Leland Richardson [G]
10/11/2019, 4:13 PMvar text by state { "Hello, World!" }
will be the way it will work. right now the +
is needed. but property delegates are indeed something i’m looking forward to being used here. they didn’t work with the new kotlin compiler backend that we rely on until recently thoughval text by State("Hello World")
compiles, but is subtly wrong, so don’t do thatFudge
10/11/2019, 4:14 PMLeland Richardson [G]
10/11/2019, 4:14 PMIcaro Temponi
10/11/2019, 4:17 PMvar text by state { "Hello, World!" }
?Leland Richardson [G]
10/11/2019, 4:21 PMIcaro Temponi
10/11/2019, 4:21 PMLeland Richardson [G]
10/11/2019, 4:22 PMstate
which is State
implements the componentN operators and the property delegate operatorsTristan Caron
10/11/2019, 4:23 PMclass CounterService {
private val counter = ConflatedBroadcastChannel(0)
fun openSubscription() = counter.openSubscription()
suspend fun increment() {
counter.send(counter.value + 1)
}
}
//
@Composable
fun MyComponent(counterService: CounterService) {
Button(onclick = { counterService.increment() })
Text(counterService.openSubscription())
}
The view would be automatically updated on new values.Leland Richardson [G]
10/11/2019, 4:24 PMTristan Caron
10/11/2019, 4:28 PMAdam Powell
10/11/2019, 9:34 PMTristan Caron
10/11/2019, 11:17 PMSequence
but async, so AsyncSequence
. And channel, for something that doesn’t, like a event. I thinking like having an UserService, and if an user change some settings, like color, it is broadcast across the app.
When a component is removed from the tree, of course, we have to think of unsubscribing. But the service will be always running.gildor
10/15/2019, 12:38 AMbroadcast across the appRight, and to subscribe on this broadcast you consume it using Flow. Under the hood it will be a channel for now, or upcoming DataFlow or Flow.share()
Tristan Caron
10/15/2019, 3:30 PMclass CounterService {
private val counter = ConflatedBroadcastChannel(0)
fun openSubscription() = counter.openSubscription()
suspend fun increment() {
counter.send(counter.value + 1)
}
}
gildor
10/15/2019, 11:26 PM