state management

This commit is contained in:
2023-08-25 09:08:14 +09:00
parent f5ef647975
commit 95477e9b40
40 changed files with 1513 additions and 8 deletions

View File

@@ -0,0 +1,24 @@
namespace BlazorStateApp.Data
{
public class CounterState
{
private int _count = 0;
public Action OnStateChanged;
public int Count
{
get { return _count; }
set
{
_count = value;
Refresh();
}
}
private void Refresh()
{
this.OnStateChanged?.Invoke();
}
}
}

View File

@@ -0,0 +1,13 @@
namespace BlazorStateApp.Data
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
namespace BlazorStateApp.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray());
}
}
}