Replies: 2 comments 10 replies
-
My suggestion here would be to change the architecture into a more declarative/reactive approach (I'm adding doc about this here #2361) To apply it to your case: namespace OsmoManager.ViewModels;
internal partial record MachineBoardModel(MachinesService MachinesService)
{
public IState<MarchineCriteria> Criteria => State.Value(this, () => new MarchineCriteria());
public IListFeed<MachinesListItem> Machines => Criteria.Select(MachinesService.GetMachinesListAsync).AsListFeed();
} internal partial record MarchineCriteria(bool Unassigned, bool Running, bool Stopped, out OutOfService);
internal class MachinesService
{
private IImmutableList<MachinesListItem> _machines = ImmutableList<MachinesListItem>.Empty;
public async ValueTask<IImmutableList<MachinesListItem>> GetMachinesListAsync(MarchineCriteria criteria, CancellationToken ct)
{
_machines = await GetFakeMachinesListAsync(ct);
int states = 0;
if (criteria.Unassigned) states |= (int)MachineStates.Unassigned;
if (criteria.Running) states |= (int)MachineStates.Running;
if (criteria.Stopped) states |= (int)MachineStates.Stopped;
if (criteria.OutOfService) states |= (int)MachineStates.OutOfService;
return _machines.Where(x => ((int)x.State & states) > 0).ToImmutableList();
}
} And you can then edit the And if you still want to let the user to refresh the list, you can also use the |
Beta Was this translation helpful? Give feedback.
-
@francoistanguay @dr1rrb Solved, Select must be SelectAsync |
Beta Was this translation helpful? Give feedback.
-
Given a model like this, and having the Machines list bound to a FeedView, how can I refresh the list every time a filter flag changes?
Beta Was this translation helpful? Give feedback.
All reactions