Implement support for stateless UIs #1418
Merged
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.
Rehash of #565. This implements support for an optimized stateless UI. These UIs either have no state or derive their state from the screen inputs.
There's three parts to this:
StaticPresenter
andStaticUi
classes. The former is just a presenter that always returns the same, lazily-computed state value. The latter is a UI that always renders the same initial static value (which can be derived from a Screen input or otherwise). Internally inCircuitContent
,StaticUi
UIs have a different code path that never wires up the presenter and instead just renders the UI directly and only the UI.StaticPresenter
instance that can be reused for circuit's internal wiring.StaticScreen
interface, which is a marker interface to indicate that a given screen is stateless and thus may not have a presenter.Circuit
internally checks this and will just return the stateless presenter singleton upon these cases.The
AboutScreen
in the STAR sample has been updated for this use case. This is particularly useful for small isolated screens where theScreen
class alone can be the only input but aCircuitContent
is still desirable for indirection.I left some toe-holds for possibly exposing some of these APIs down the line, but kept things limited for now.