Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wihrl committed Feb 15, 2024
1 parent 6a6e60c commit a83b03d
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 60 deletions.
1 change: 0 additions & 1 deletion PropReact.Tests/Collections/ListTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PropReact.Chain;
using PropReact.Props;
using PropReact.Props.Collections;
using PropReact.Props.Value;
using PropReact.Utils;
Expand Down
3 changes: 1 addition & 2 deletions PropReact.Tests/Collections/MapTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PropReact.Chain;
using PropReact.Props;
using PropReact.Props.Collections;
using PropReact.Props.Value;
using PropReact.Utils;
Expand Down Expand Up @@ -171,7 +170,7 @@ public void ListWatchAt()
var changes = 0;
int expected = 0;

var guids = Enumerable.Range(0, 2).Select(x => Guid.NewGuid()).ToArray();
var guids = Enumerable.Range(0, 2).Select(_ => Guid.NewGuid()).ToArray();

ChainBuilder.From(this)
.ChainConstant(x => x.Data.Records)
Expand Down
6 changes: 0 additions & 6 deletions PropReact.Tests/ComplexTests.cs

This file was deleted.

17 changes: 8 additions & 9 deletions PropReact.Tests/ReactionTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using PropReact.Chain;
using PropReact.Props;
using PropReact.Props.Value;
using PropReact.Utils;

Expand Down Expand Up @@ -55,7 +54,7 @@ void ThrottledInternal(bool immediate)

ChainBuilder.From(this)
.ChainValue(x => x._int)
.Throttled(delay, ThrottleMode.Extendable | ThrottleMode.ImmediateExtendable)
.Throttled(delay, immediate ? ThrottleMode.Extendable | ThrottleMode.ImmediateExtendable : ThrottleMode.Extendable)
.React(() =>
{
counter++;
Expand All @@ -65,12 +64,13 @@ void ThrottledInternal(bool immediate)

Assert.Equal(expected, counter);

var time = sw.ElapsedMilliseconds;
long time;

void TriggerInitial()
{
_int.Value++;
Assert.Equal(++expected, counter);

Assert.Equal(immediate ? ++expected : expected, counter);
ready = false;
time = sw.ElapsedMilliseconds;
}
Expand Down Expand Up @@ -127,7 +127,6 @@ void Async()
{
var counter = 0;
var expected = 0;
var sw = Stopwatch.StartNew();

ChainBuilder.From(this)
.ChainValue(x => x._int)
Expand Down Expand Up @@ -155,17 +154,17 @@ void Async()
void AsyncException()
{
var caught = false;
var sw = Stopwatch.StartNew();
Stopwatch.StartNew();

ChainBuilder.From(this)
.ChainValue(x => x._int)
.Immediate()
.ReactAsync(async x =>
.ReactAsync(async _ =>
{
await Task.Yield();
throw new Exception();
throw new();
})
.CatchAsync(x => caught = true)
.CatchAsync(_ => caught = true)
.Start(this);

_int.Value++;
Expand Down
26 changes: 13 additions & 13 deletions PropReact.Tests/TypeTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System.Runtime.CompilerServices;
using PropReact.Chain;
using PropReact.Chain.Nodes;
using PropReact.Props;
using PropReact.Chain;
using PropReact.Props.Collections;
using PropReact.Props.Value;
// ReSharper disable All
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value

namespace PropReact.Tests;

/// <summary>
/// Checks that "type inference" overloads compile, does not check runtime logic.
/// This "test" can be useful when messing around with ChainBuilder generics.
/// </summary>
public partial class TypeTests
public class TypeTests
{
class ValueTypeData
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public void Mixed()
{
A root = null!;

var p1 = ChainBuilder.From(root)
ChainBuilder.From(root)
.ChainValue(x => x.B)
.ChainValue(x => x.C)
.Branch(
Expand All @@ -83,25 +83,25 @@ public void Mixed()
.Immediate()
.React(() => { });

var p2 = ChainBuilder.From(root)
ChainBuilder.From(root)
.ChainValue(x => x.B)
.ChainValue(x => x.C)
.ChainConstant(x => x.Ele)
.Enter()
.Enter()
.ChainValue(x => x.E1)
.Immediate()
.Compute(() => root.B.Value.C.Value.Ele.Select(x => x.Select(y => y.E1.v)), out var d0);
.Compute(() => root.B.Value.C.Value.Ele.Select(x => x.Select(y => y.E1.v)), out _);

var p3 = ChainBuilder.From(root)
ChainBuilder.From(root)
.ChainValue(x => x.B)
.ChainValue(x => x.ListOfC)
.Enter()
.ChainValue(x => x.D1)
.Immediate()
.React(() => { });

var p4 = ChainBuilder.From(root)
ChainBuilder.From(root)
.ChainValue(x => x.B)
.ChainValue(x => x.IListOfC)
.Enter()
Expand All @@ -110,20 +110,20 @@ public void Mixed()
.ChainValue(x => x.D1)
.Immediate();

var p5 = ChainBuilder.From(root)
ChainBuilder.From(root)
.ChainValue(x => x.B)
.ChainValue(x => x.C)
.ChainConstant(x => x.Emap)
.EnterAt("asdf")
.ChainValue(x => x.E1)
.Immediate();

var p6 = ChainBuilder.From(root)
ChainBuilder.From(root)
.ChainValue(x => x.Blist)
.Enter()
.ChainValue(x => x.C)
.Immediate()
.Compute(() => "", out var d1)
.Compute(() => "", out _)
.StartAsDisposable();
}

Expand Down
1 change: 0 additions & 1 deletion PropReact.Tests/ValidationTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PropReact.Chain;
using PropReact.Props;
using PropReact.Tests.Shared;

namespace PropReact.Tests;
Expand Down
1 change: 0 additions & 1 deletion PropReact.Tests/ValueTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PropReact.Chain;
using PropReact.Props;
using PropReact.Tests.Shared;
using PropReact.Utils;
using Record = PropReact.Tests.Shared.Record;
Expand Down
18 changes: 5 additions & 13 deletions PropReact/Chain/ChainBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@

namespace PropReact.Chain;

public interface IBranchType
{
}

public struct RootBranch : IBranchType
{
}

public struct InnerBranch : IBranchType
{
}
public interface IBranchType;
public struct RootBranch : IBranchType;
public struct InnerBranch : IBranchType;

public class ChainBuilder<TRoot, TBranchType, TValue> where TBranchType : IBranchType
{
Expand Down Expand Up @@ -51,7 +43,7 @@ public static ChainBuilder<TRoot, RootBranch, TRoot> From<TRoot>(
#region Values

public static ChainBuilder<TMainRoot, TBranchType, TNext> ChainValue<TMainRoot, TBranchType, TValue, TNext>(
this ChainBuilder<TMainRoot, TBranchType, TValue> builder, Func<TValue, IValue<TNext>> selector,
this ChainBuilder<TMainRoot, TBranchType, TValue> builder, Func<TValue, IValue<TNext?>> selector,
[CallerArgumentExpression(nameof(selector))]
string expression = "")
where TBranchType : IBranchType
Expand All @@ -72,7 +64,7 @@ Appending a non-constant node to a reactive chain must be done one property at a
nameof(selector));
#endif

var nextNode = new ValueNode<TValue, TNext>(selector, builder.RootNode);
var nextNode = new ValueNode<TValue, TNext>(selector!, builder.RootNode);
builder.Node.Chain(nextNode);

return new(
Expand Down
10 changes: 5 additions & 5 deletions PropReact/Chain/Reactions/Reaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ abstract class Reaction<TRoot> : IReactionBuilder<TRoot>, IDisposable
{
private event Action? Reactions;
private event Func<CancellationToken, ValueTask>? AsyncReactions;
private Action<Exception>? AsyncExceptionHandler;


private Action<Exception>? _asyncExceptionHandler;
private CancellationTokenSource _cts = new();

private readonly RootNode<TRoot> _root;
Expand All @@ -49,7 +49,7 @@ IReactionBuilder<TRoot> IReactionBuilder<TRoot>.ReactAsync(Func<CancellationToke
}
catch (Exception e)
{
AsyncExceptionHandler?.Invoke(e);
_asyncExceptionHandler?.Invoke(e);
}
};

Expand Down Expand Up @@ -96,7 +96,7 @@ IReactionBuilder<TRoot> IReactionBuilder<TRoot>.ComputeAsync<TValue>(
}
catch (Exception e)
{
AsyncExceptionHandler?.Invoke(e);
_asyncExceptionHandler?.Invoke(e);
}
finally
{
Expand All @@ -112,7 +112,7 @@ IReactionBuilder<TRoot> IReactionBuilder<TRoot>.ComputeAsync<TValue>(

IReactionBuilder<TRoot> IReactionBuilder<TRoot>.CatchAsync(Action<Exception> handler)
{
AsyncExceptionHandler += handler;
_asyncExceptionHandler += handler;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion PropReact/Props/Collections/ReactiveList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void RemoveAt(int index)

// if the removed item is not the last, notify existing observers of shifted indices
if (index < _list.Count /* list.Count-=1 because of removal */ && KeyedObservers is not null)
foreach (var (key, observers) in KeyedObservers.Where(x => x.Key > index))
foreach (var (_, observers) in KeyedObservers.Where(x => x.Key > index))
foreach (var propObserver in observers)
propObserver.PropChanged(InternalGetter(index), InternalGetter(index + 1));
}
Expand Down
4 changes: 1 addition & 3 deletions PropReact/Props/GenericObserver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using PropReact.Props.Value;

namespace PropReact.Props;
namespace PropReact.Props;

internal class GenericObserver<T>(IProp<T> prop, Action<T?, T?> action) : IPropObserver<T>, IDisposable
{
Expand Down
2 changes: 1 addition & 1 deletion samples/BlazorSample/Components/Pages/Counter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
_count.Value++;
}

int _renderCount = 0;
int _renderCount;
protected override void OnAfterRender(bool firstRender) => _renderCount++;
}
2 changes: 1 addition & 1 deletion samples/BlazorSample/Components/Pages/Exclusive.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
readonly Mutable<string> _color = new("#ff0000");
readonly Mutable<string> _text = new("sample text");

int _renderCount = 0;
int _renderCount;

protected override void OnAfterRenderInternal(bool firstRender)
{
Expand Down
3 changes: 1 addition & 2 deletions samples/BlazorSample/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@inherits PropReact.Blazor.ExclusiveReactiveComponent
@using PropReact.Props.Value
@using PropReact.Chain
@using PropReact
@using PropReact.Utils

@code {
Expand All @@ -27,7 +26,7 @@
}


int _renderCount = 0;
int _renderCount;
protected override void OnAfterRenderInternal(bool firstRender)
{
_renderCount++;
Expand Down
1 change: 0 additions & 1 deletion samples/BlazorSample/Components/Pages/Weather.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@page "/weather"
@using PropReact.Props.Value
@using PropReact.Chain
@using PropReact
@inherits PropReact.Blazor.ReactiveComponent

<PageTitle>Weather</PageTitle>
Expand Down

0 comments on commit a83b03d

Please sign in to comment.