Blazor by Example - A spot of refactoring

added by DotNetKicks
2/10/2020 9:19:17 AM

377 Views

Here's where we got to last time in building a traffic light using Blazor. TrafficLight.razor.cs public class TrafficLightBase : ComponentBase { private State _currentState = State.Stop; protected TrafficLightState Lights => TrafficLightState.Resolve(_currentState); public void Toggle() { _currentState = _currentState switch { State.Stop => State.GetReadyToGo, State.GetReadyToGo => State.Go, State.Go => State.GetReadyToStop, State.GetReadyToStop => State.Stop, _ => _currentState }; } } _currentState refers to an enum.


0 comments