loloof64
04/19/2021, 6:48 PMmutableStateOf()
has an immutable version ? Or would that have no sense ? Because I want to have a state, but that would never change : just in order to avoid to create it each timeSean McQuillan [G]
04/19/2021, 6:49 PMState<T>
/ MutableState<T>
you can think of this as
List<T>
/ MutableList<T>
Sean McQuillan [G]
04/19/2021, 6:49 PMT
loloof64
04/19/2021, 6:50 PMSean McQuillan [G]
04/19/2021, 6:50 PMval neverChanges = someThing
or if it's expensive
val neverChanges = remember { someThing }
Sean McQuillan [G]
04/19/2021, 6:50 PMval neverChanges = remember(o1, o2) { o1.someThing(o2) }
loloof64
04/19/2021, 6:51 PMSean McQuillan [G]
04/19/2021, 6:51 PMloloof64
04/19/2021, 6:52 PMval neverChanges = remember { someThing }
: this one could save me 🙂Sean McQuillan [G]
04/19/2021, 6:52 PMloloof64
04/19/2021, 6:53 PMSean McQuillan [G]
04/19/2021, 6:55 PMclass MyClass(initialValue: SomeType) {
var someState by mutableStateOf(initialValue)
private set
}
(initialValue obv. optional but worth showing)Casey Brooks
04/19/2021, 6:57 PMState<T>
doesn’t imply that the value won’t change, it just implies that it can’t be mutated externally. Whatever logic implements the State<T>
interface can change its own internal value and kickstart recomposition, but you get the guarantee of knowing exactly where its being changed from (such as with Flow.collectAsState()
). If it truly never changes, it should just be a normal value not wrapped in State<T>
loloof64
04/19/2021, 7:01 PMval enginesUtils = rememberSaveable {
ChessEngineUtils(
appId = myAppId,
context = currentContext
)
}
Where ChessEngineUtils
is the utility class.Sean McQuillan [G]
04/19/2021, 7:03 PMmyAppId
and currentContext
are suspicious in a remember block without parameters. If they change should ChessEngineUtils
be re-instantiated?Sean McQuillan [G]
04/19/2021, 7:03 PMSean McQuillan [G]
04/19/2021, 7:03 PMrememberSavable(myAppId, currentContext) { ... }
loloof64
04/19/2021, 7:07 PM