pavi2410
07/04/2019, 2:39 PM@State var count = 0
while in Compose, val count = +state { 0 }
. Why such a hacky thing (+state
) is chosen?count.value = 1
as opposed to count = 1
.
The latter is cleaner.matvei
07/04/2019, 2:43 PM@Model
data class CountModel(var count: Int = 0)
The +
is the syntax for effects, which is subject to change, but essentially it's main purpose to give Compose knowledge about some building blocks that are not UI, so runtime can memorize and reuse it or call in at specific moments, such as compose lifecyclesval state = State(0)
pavi2410
07/04/2019, 2:44 PMmatvei
07/04/2019, 2:44 PMpavi2410
07/04/2019, 2:45 PMvar count = 0
var count by state { 0 }
matvei
07/04/2019, 2:47 PMvar count by +state { 0 }
should workpavi2410
07/04/2019, 2:49 PMmatvei
07/04/2019, 2:51 PMLeland Richardson [G]
07/04/2019, 4:27 PMval count = state { 0 }
and var count by state { 0 }
will also work if you prefer that (basically, current API just without the + being needed)Adam Powell
07/04/2019, 4:27 PMLeland Richardson [G]
07/04/2019, 4:28 PMlouiscad
07/04/2019, 5:25 PMAdam Powell
07/04/2019, 5:54 PMlouiscad
07/04/2019, 7:14 PMAdam Powell
07/04/2019, 7:16 PMkrtko
07/05/2019, 5:57 PM@State
annotation is clearer than using a +
to denote a UI state variable.pavi2410
07/06/2019, 3:22 AMjim
07/08/2019, 10:48 AM+memo
requires realizing that you're supposed to also specify an invalidation set of all the parameters used to calculate the memoized expression. If you miss one, your code will be subtly wrong. Using an annotation instead would allow the compiler to calculate the invalidation set of the expression, thus avoiding bugs. This has been the topic of a few hallway discussions; it's potentially a space worth exploring further.