Skip to content

Instantly share code, notes, and snippets.

@Clancey
Created February 9, 2022 21:16
Show Gist options
  • Save Clancey/0d9bf071e7888382a351a65bf9374349 to your computer and use it in GitHub Desktop.
Save Clancey/0d9bf071e7888382a351a65bf9374349 to your computer and use it in GitHub Desktop.
Comet with pure MVU, without any state.
public class RideTheComet : View
{
public record CometRide
{
public int Rides { get; init; } = 0;
public string CometTrain => "☄️".Repeat(Rides);
}
CometRide state = new CometRide();
[Body]
View body() => new VStack {
new Text(()=> $"({state.Rides}) rides taken:{state.CometTrain}"),
new Button("Ride the Comet! ☄️", () => {
state = state with {Rides = state.Rides + 1};
this.Reload();
})
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment