Skip to content

Commit

Permalink
Fix long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nabond251 committed Feb 1, 2024
1 parent 5cb02d0 commit 5e004ce
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/Rearch/BuiltinSideEffectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public static Action Rebuilder(this ISideEffectRegistrar registrar) =>
/// Side effect that calls the supplied <paramref name="callback"/> once,
/// on the first build.
/// </summary>
/// <typeparam name="T">Type of side effect <paramref name="callback"/> result.</typeparam>
/// <typeparam name="T">
/// Type of side effect <paramref name="callback"/> result.
/// </typeparam>
/// <param name="registrar">Side effect registrar.</param>
/// <param name="callback">Callback to be called once.</param>
/// <returns><paramref name="callback"/> result.</returns>
Expand Down
6 changes: 4 additions & 2 deletions src/Rearch/CapsuleHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Rearch;

/// <summary>
/// Implementation of the handle given to a <see cref="Capsule{T}"/> to build its data.
/// Implementation of the handle given to a <see cref="Capsule{T}"/> to build its
/// data.
/// </summary>
internal sealed class CapsuleHandle(UntypedCapsuleManager manager) : ICapsuleHandle
internal sealed class CapsuleHandle(UntypedCapsuleManager manager) :
ICapsuleHandle
{
/// <summary>
/// Gets the capsule manager for this handle.
Expand Down
4 changes: 3 additions & 1 deletion src/Rearch/CapsuleManager{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public override bool BuildSelf()
!this.HasBuilt ||
(newData is null && this.Data is not null) ||
(newData is not null && this.Data is null) ||
(newData is not null && this.Data is not null && !newData.Equals(this.Data));
(
newData is not null && this.Data is not null &&
!newData.Equals(this.Data));
this.Data = newData;
this.HasBuilt = true;
return didChange;
Expand Down
10 changes: 7 additions & 3 deletions src/Rearch/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ public T Read<T>(Capsule<T> capsule) =>
this.Manager(capsule).Data;

/// <summary>
/// <i>Temporarily</i> listens to changes in a given set of <see cref="Capsule{T}"/>s.
/// <i>Temporarily</i> listens to changes in a given set of
/// <see cref="Capsule{T}"/>s.
/// If you want to listen to capsule(s) <i>not temporarily</i>,
/// instead just make an impure capsule and <see cref="Read{T}(Capsule{T})"/> it once to initialize it.
/// instead just make an impure capsule and
/// <see cref="Read{T}(Capsule{T})"/> it once to initialize it.
/// <c>Listen</c> calls the supplied listener immediately,
/// and then after any capsules its listening to change.
/// </summary>
/// <param name="listener">Capsule listener.</param>
/// <returns>Listener handle to dispose when done listening.</returns>
/// <remarks><see cref="ListenerHandle"/> will leak its listener if it is not disposed.</remarks>
/// <remarks>
/// <see cref="ListenerHandle"/> will leak its listener if it is not disposed.
/// </remarks>
public ListenerHandle Listen(CapsuleListener listener)
{
// Create a temporary *impure* capsule so that it doesn't get super-pure
Expand Down
10 changes: 7 additions & 3 deletions src/Rearch/DataflowGraphNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ private List<DataflowGraphNode> CreateBuildOrder()
// in order to do the topological sort:
// - False is for the first visit, which adds all deps to be visited,
// and then node again
// - True is for the second visit, which pushes the node to the build order
// - True is for the second visit, which pushes the node to the build
// order
var toVisitStack = new List<(bool, DataflowGraphNode)>
{
(false, this),
Expand All @@ -182,9 +183,12 @@ private List<DataflowGraphNode> CreateBuildOrder()
}
else
{
// New node, so mark this node to be added later and process dependents
// New node, so mark this node to be added later and process
// dependents
visited.Add(node);
toVisitStack.Add((true, node)); // mark to be added to build order later

// mark to be added to build order later
toVisitStack.Add((true, node));
node.dependents
.Where(dep => !visited.Contains(dep))
.ToList()
Expand Down
7 changes: 5 additions & 2 deletions src/Rearch/ISideEffectRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ namespace Rearch;
/// See the documentation for more.
/// </summary>
/// <typeparam name="T">Type of side effect result.</typeparam>
/// <param name="sideEffectApi">The API to create this side effect's state.</param>
/// <param name="sideEffectApi">
/// The API to create this side effect's state.
/// </param>
/// <returns>Side effect result.</returns>
public delegate T SideEffect<out T>(ISideEffectApi sideEffectApi);

/// <summary>
/// Provides a mechanism (<see cref="Register{T}(SideEffect{T})"/>) to register side effects.
/// Provides a mechanism (<see cref="Register{T}(SideEffect{T})"/>) to register
/// side effects.
/// </summary>
public interface ISideEffectRegistrar
{
Expand Down
3 changes: 2 additions & 1 deletion src/Rearch/ListenerHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace Rearch;

/// <summary>
/// A handle onto the lifecycle of a listener from <see cref="Container.Listen(CapsuleListener)"/>.
/// A handle onto the lifecycle of a listener from
/// <see cref="Container.Listen(CapsuleListener)"/>.
/// You <i>must</i> <see cref="Dispose()"/> the <see cref="ListenerHandle"/>
/// when you no longer need the listener in order to prevent leaks.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Rearch/UntypedCapsuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace Rearch;
/// <summary>
/// Base untyped dataflow node that manages capsule data and effects.
/// </summary>
internal abstract class UntypedCapsuleManager(Container container) : DataflowGraphNode,
internal abstract class UntypedCapsuleManager(Container container) :
DataflowGraphNode,
ISideEffectApi
{
/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions tests/Rearch.Example.Tests/ExampleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ public void MainFunctionRunsCorrectly()
"CountPlusOne should be 2 after count increment");
}

private static (int Count, Action<int> SetCount) CountManager(ICapsuleHandle use) => use.State(0);
private static (int Count, Action<int> SetCount) CountManager(
ICapsuleHandle use) =>
use.State(0);

private static Action CountIncrementer(ICapsuleHandle use)
{
var (count, setCount) = use.Invoke(CountManager);
return () => setCount(count + 1);
}

private static int Count(ICapsuleHandle use) => use.Invoke(CountManager).Count;
private static int Count(ICapsuleHandle use) =>
use.Invoke(CountManager).Count;

private static int CountPlusOne(ICapsuleHandle use) => use.Invoke(Count) + 1;
}
12 changes: 8 additions & 4 deletions tests/Rearch.Tests/BasicTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public void ListenerGetsUpdates()
void SetState(int state) => container.Read(Stateful).Item2(state);

List<int> states = [];
void Listener(ICapsuleReader use) => states.Add(use.Invoke(Stateful).Item1);
void Listener(ICapsuleReader use) =>
states.Add(use.Invoke(Stateful).Item1);

SetState(1);
var handle1 = container.Listen(Listener);
Expand Down Expand Up @@ -188,7 +189,8 @@ int UnchangingSuperPureDep(ICapsuleHandle use)
}
else
{
builds[(object)UnchangingSuperPureDep] = builds[(object)UnchangingSuperPureDep] + 1;
builds[(object)UnchangingSuperPureDep] =
builds[(object)UnchangingSuperPureDep] + 1;
}

use.Invoke(Stateful);
Expand Down Expand Up @@ -217,7 +219,8 @@ int ChangingSuperPureDep(ICapsuleHandle use)
}
else
{
builds[(object)ChangingSuperPureDep] = builds[(object)ChangingSuperPureDep] + 1;
builds[(object)ChangingSuperPureDep] =
builds[(object)ChangingSuperPureDep] + 1;
}

return use.Invoke(Stateful).Item1;
Expand All @@ -231,7 +234,8 @@ int ChangingWatcher(ICapsuleHandle use)
}
else
{
builds[(object)ChangingWatcher] = builds[(object)ChangingWatcher] + 1;
builds[(object)ChangingWatcher] =
builds[(object)ChangingWatcher] + 1;
}

return use.Invoke(ChangingSuperPureDep);
Expand Down

0 comments on commit 5e004ce

Please sign in to comment.