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

Implement support for stateless UIs #1418

Merged
merged 6 commits into from
May 22, 2024
Merged

Implement support for stateless UIs #1418

merged 6 commits into from
May 22, 2024

Conversation

ZacSweers
Copy link
Collaborator

@ZacSweers ZacSweers commented May 19, 2024

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:

  1. The introduction of internal StaticPresenter and StaticUi 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 in CircuitContent, StaticUi UIs have a different code path that never wires up the presenter and instead just renders the UI directly and only the UI.
  2. The introduction of a "stateless" presenter, which is just a singleton StaticPresenter instance that can be reused for circuit's internal wiring.
  3. The introduction of a 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 the Screen class alone can be the only input but a CircuitContent 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.

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:
1. The introduction of internal `StaticPresenter` and `StaticUi` 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 in `CircuitContent`, `StaticUi` UIs have a different code path that never wires up the presenter and instead just renders the UI directly and only the UI.
2. The introduction of a "stateless" presenter, which is just a singleton `StaticPresenter` instance that can be reused for circuit's internal wiring.
3. The introduction of a `StatelessScreen` 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.
@ZacSweers ZacSweers requested a review from stagg May 19, 2024 03:32
@ZacSweers ZacSweers marked this pull request as ready for review May 19, 2024 03:32
Copy link
Collaborator

@stagg stagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@stagg stagg added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit f204921 May 22, 2024
5 checks passed
@stagg stagg deleted the z/statelessv2 branch May 22, 2024 16:57
This was referenced May 23, 2024
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

2 participants