Skip to content

Commit 2267832

Browse files
committed
chore: turn Step and Count into record
1 parent 5611d65 commit 2267832

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
namespace Counter;
22

3+
internal partial record Countable(int Count, int Step)
4+
{
5+
public Countable Increment() => this with
6+
{
7+
Count = Count + Step
8+
};
9+
}
10+
311
internal partial record MainModel
412
{
5-
public IState<int> Count => State.Value(this, () => 0);
13+
public IState<Countable> Countable => State.Value(this, () => new Countable(0, 1));
614

7-
public IState<int> Step => State.Value(this, () => 1);
8-
9-
public ValueTask IncrementCommand(int Step)
10-
=> Count.Update(c => c + Step, CancellationToken.None);
15+
public ValueTask IncrementCommand()
16+
=> Countable.Update(c => c?.Increment(), CancellationToken.None);
1117
}

reference/Counter/CSharp-MVUX/Counter/MainPage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public MainPage()
2121
.HorizontalAlignment(HorizontalAlignment.Center)
2222
.TextAlignment(Microsoft.UI.Xaml.TextAlignment.Center)
2323
.PlaceholderText("Step Size")
24-
.Text(x => x.Bind(() => vm.Step).TwoWay()),
24+
.Text(x => x.Bind(() => vm.Countable.Step).TwoWay()),
2525
new TextBlock()
2626
.Margin(12)
2727
.HorizontalAlignment(HorizontalAlignment.Center)
2828
.TextAlignment(Microsoft.UI.Xaml.TextAlignment.Center)
29-
.Text(() => vm.Count, txt => $"Counter: {txt}"),
29+
.Text(() => vm.Countable.Count, txt => $"Counter: {txt}"),
3030
new Button()
3131
.Margin(12)
3232
.HorizontalAlignment(HorizontalAlignment.Center)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Counter;
2+
3+
internal partial record Countable(int Count, int Step)
4+
{
5+
public Countable Increment() => this with
6+
{
7+
Count = Count + Step
8+
};
9+
}

reference/Counter/XAML-MVUX/Counter/MainModel.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ namespace Counter;
22

33
internal partial record MainModel
44
{
5-
public IState<int> Count => State.Value(this, () => 0);
5+
public IState<Countable> Countable => State.Value(this, () => new Countable(0, 1));
66

7-
public IState<int> Step => State.Value(this, () => 1);
8-
9-
public ValueTask IncrementCommand(int Step)
10-
=> Count.Update(c => c + Step, CancellationToken.None);
7+
public ValueTask IncrementCommand() =>
8+
Countable.Update(c => c?.Increment(), CancellationToken.None);
119
}

reference/Counter/XAML-MVUX/Counter/MainPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
Margin="12"
2020
HorizontalAlignment="Center"
2121
PlaceholderText="Step Size"
22-
Text="{Binding Step, Mode=TwoWay}"
22+
Text="{Binding Countable.Step, Mode=TwoWay}"
2323
TextAlignment="Center" />
2424

2525
<TextBlock
2626
Margin="12"
2727
HorizontalAlignment="Center"
2828
TextAlignment="Center">
29-
<Run Text="Counter: " /><Run Text="{Binding Count}" />
29+
<Run Text="Counter: " /><Run Text="{Binding Countable.Count}" />
3030
</TextBlock>
3131

3232
<Button

0 commit comments

Comments
 (0)