Expand description
DataResource: typed async data lifecycle
A type representing the lifecycle of async-loaded data. Use this instead of
scattering loading: bool and error: Option<String> across your state.
§Example
use tui_dispatch_core::DataResource;
// In state
struct AppState {
weather: DataResource<WeatherData>,
}
// In reducer
match action {
Action::FetchWeather => {
state.weather = DataResource::Loading;
// return effect to fetch
}
Action::WeatherDidLoad(data) => {
state.weather = DataResource::Loaded(data);
}
Action::WeatherDidFail(err) => {
state.weather = DataResource::Failed(err);
}
}
// In render
match &state.weather {
DataResource::Empty => { /* show placeholder */ }
DataResource::Loading => { /* show spinner */ }
DataResource::Loaded(data) => { /* render data */ }
DataResource::Failed(err) => { /* show error */ }
}Enums§
- Data
Resource - Represents the lifecycle of async-loaded data.