Skip to content

Commit 7174d8a

Browse files
committed
chore: Using getter syntax and refactoring the models
1 parent bd0c74e commit 7174d8a

File tree

2 files changed

+15
-35
lines changed

2 files changed

+15
-35
lines changed

UI/MVUX/src/MVUX/Presentation/FeedViewCommandSample/FeedViewCommandModel.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ public partial class FeedViewCommandModel
1010

1111
public async ValueTask RemoveItem(Item item)
1212
{
13-
if (item != null)
14-
{
15-
await Items.UpdateAsync(currentItems => currentItems.Remove(item));
16-
}
13+
await Items.UpdateAsync(currentItems => currentItems.Remove(item));
1714
}
1815
}
1916

UI/MVUX/src/MVUX/Presentation/FeedViewSample/FeedViewModel.cs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,36 @@ namespace MVUX.Presentation.FeedViewSample;
44

55
public partial record FeedViewModel
66
{
7-
private readonly Random _random = new();
8-
9-
public IFeed<Person> DefaultPerson { get; }
10-
11-
public IFeed<Person> CustomLoadingPerson { get; }
12-
13-
public IFeed<Person> ErrorPerson { get; }
14-
15-
public FeedViewModel()
7+
private static readonly Person[] _people = new[]
168
{
17-
DefaultPerson = Feed.Async(GetRandomPersonAsync);
9+
new Person("Master", "Yoda"),
10+
new Person("Darth", "Vader"),
11+
new Person("Luke", "Skywalker"),
12+
};
1813

19-
CustomLoadingPerson = Feed.Async(GetRandomPersonWithLargerDelayAsync);
14+
public IFeed<Person> DefaultPerson => Feed.Async(GetRandomPersonAsync);
2015

21-
ErrorPerson = Feed.Async(ThrowErrorAsync);
22-
}
16+
public IFeed<Person> CustomLoadingPerson => Feed.Async(GetRandomPersonWithLargerDelayAsync);
17+
18+
public IFeed<Person> ErrorPerson => Feed.Async(ThrowErrorAsync);
2319

2420
private async ValueTask<Person> GetRandomPersonAsync(CancellationToken ct)
2521
{
22+
// This simulates a network delay
2623
await Task.Delay(2000, ct);
27-
28-
var people = new[]
29-
{
30-
new Person("Master", "Yoda"),
31-
new Person("Darth", "Vader"),
32-
new Person("Luke", "Skywalker"),
33-
};
34-
35-
return people[_random.Next(0, people.Length)];
24+
return _people[Random.Shared.Next(_people.Length)];
3625
}
3726

3827
private async ValueTask<Person> GetRandomPersonWithLargerDelayAsync(CancellationToken ct)
3928
{
29+
// This simulates a network delay
4030
await Task.Delay(5000, ct);
41-
42-
var people = new[]
43-
{
44-
new Person("Master", "Yoda"),
45-
new Person("Darth", "Vader"),
46-
new Person("Luke", "Skywalker"),
47-
};
48-
49-
return people[_random.Next(0, people.Length)];
31+
return _people[Random.Shared.Next(_people.Length)];
5032
}
5133

5234
private async ValueTask<Person> ThrowErrorAsync(CancellationToken ct)
5335
{
36+
// This simulates a network delay
5437
await Task.Delay(2000, ct);
5538
throw new Exception("An error occurred while fetching the person details.");
5639
}

0 commit comments

Comments
 (0)