Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce State v2 #88

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Introduce State v2 #88

wants to merge 8 commits into from

Conversation

Johni0702
Copy link
Contributor

Most significant changes compared to v1:

  • State is now an interface instead of an abstract class
  • MutableState is a separate interface and implementations are generally expected to forward set to their source states (whereas before, a set would only ever affect the state it was called on, and would frequently get overwritten if one of its input states changed)
  • Listeners (and derived states) are weakly linked (as in WeakReference) by default, this allows a child component to transparently use the state of its parent without potentially leaking the child component memory
  • The combinators no longer allow rebinding (and no longer return special types; they are much simpler in general now), instead there's a dedicated DelegatingState which can be wrapped around an input where rebinding is required
  • Combinator functions are now all extension functions (previously some of them were defined as part of State directly)
  • New general 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 new MutableState, 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 new State with the State.toV1() extension function.

As an example, the MarkdownComponent and the PixelConstraint have been converted to use/support the new v2 API for their existing functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant