Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Most significant changes compared to v1:
State
is now an interface instead of an abstract classMutableState
is a separate interface and implementations are generally expected to forwardset
to their source states (whereas before, aset
would only ever affect the state it was called on, and would frequently get overwritten if one of its input states changed)WeakReference
) by default, this allows a child component to transparently use the state of its parent without potentially leaking the child component memoryrebind
ing (and no longer return special types; they are much simpler in general now), instead there's a dedicatedDelegatingState
which can be wrapped around an input where rebinding is requiredState
directly)derivedState
builder function to create a state which is derived from any number of other states (all the combinators are based on this)This new API should be fully compatible and be able to coexist with the legacy State API:
To use a v2 API with v1 states, the old
State
class extends the newMutableState
, so people still using the old API can transparently use functionality designed for the new API.To use a v1 API with v2 states, a old
State
instance can be created from a newState
with theState.toV1()
extension function.As an example, the
MarkdownComponent
and thePixelConstraint
have been converted to use/support the new v2 API for their existing functionality.