Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
References #5.

commit 595ba47
Author: Jan-Willem Spuij <[email protected]>
Date:   Tue Nov 26 17:48:41 2019 +0100

    Formatting.

commit ad385e1
Author: Jan-Willem Spuij <[email protected]>
Date:   Tue Nov 26 17:37:15 2019 +0100

    Convenience methods for unit tests.
    References #5.

commit 0957bda
Author: Jan-Willem Spuij <[email protected]>
Date:   Mon Nov 25 23:03:08 2019 +0100

    comments

commit 9cdb534
Author: Jan-Willem Spuij <[email protected]>
Date:   Mon Nov 25 22:59:56 2019 +0100

    Bugfix reentrancy

commit aaa9b2b
Author: Jan-Willem Spuij <[email protected]>
Date:   Mon Nov 25 13:48:24 2019 +0100

    More work on unit tests.

commit 261049a
Author: Jan-Willem Spuij <[email protected]>
Date:   Sun Nov 24 22:31:29 2019 +0100

    More unit tests.

commit 2899f90
Author: Jan-Willem Spuij <[email protected]>
Date:   Sun Nov 24 17:38:15 2019 +0100

    Start with unit tests. Implemented Computed Value observe.
  • Loading branch information
jspuij committed Nov 28, 2019
1 parent 30ff35e commit 02c08ca
Show file tree
Hide file tree
Showing 13 changed files with 979 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Cortex.Net/Api/ActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static partial class ActionExtensions
/// <param name="action">The action itself.</param>
public static void RunInAction(this ISharedState sharedState, Action action)
{
CreateAction(sharedState, null, null, action)();
CreateAction(sharedState, "<unnamed action>", null, action)();
}

/// <summary>
Expand Down
34 changes: 17 additions & 17 deletions src/Cortex.Net/Api/ActionExtensions.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static partial class ActionExtensions
/// <param name="action">The action itself.</param>
public static Action CreateAction(this ISharedState sharedState, Action action)
{
return CreateAction(sharedState, null, null, action);
return CreateAction(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -80,7 +80,7 @@ public static Action CreateAction(this ISharedState sharedState, string actionNa
/// <param name="action">The action itself.</param>
public static Action<T1> CreateAction<T1>(this ISharedState sharedState, Action<T1> action)
{
return CreateAction<T1>(sharedState, null, null, action);
return CreateAction<T1>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -128,7 +128,7 @@ public static Action<T1> CreateAction<T1>(this ISharedState sharedState, string
/// <param name="action">The action itself.</param>
public static Action<T1,T2> CreateAction<T1,T2>(this ISharedState sharedState, Action<T1,T2> action)
{
return CreateAction<T1,T2>(sharedState, null, null, action);
return CreateAction<T1,T2>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -176,7 +176,7 @@ public static Action<T1,T2> CreateAction<T1,T2>(this ISharedState sharedState, s
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3> CreateAction<T1,T2,T3>(this ISharedState sharedState, Action<T1,T2,T3> action)
{
return CreateAction<T1,T2,T3>(sharedState, null, null, action);
return CreateAction<T1,T2,T3>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -224,7 +224,7 @@ public static Action<T1,T2,T3> CreateAction<T1,T2,T3>(this ISharedState sharedSt
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4> CreateAction<T1,T2,T3,T4>(this ISharedState sharedState, Action<T1,T2,T3,T4> action)
{
return CreateAction<T1,T2,T3,T4>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -272,7 +272,7 @@ public static Action<T1,T2,T3,T4> CreateAction<T1,T2,T3,T4>(this ISharedState sh
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5> CreateAction<T1,T2,T3,T4,T5>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5> action)
{
return CreateAction<T1,T2,T3,T4,T5>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -320,7 +320,7 @@ public static Action<T1,T2,T3,T4,T5> CreateAction<T1,T2,T3,T4,T5>(this ISharedSt
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6> CreateAction<T1,T2,T3,T4,T5,T6>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -368,7 +368,7 @@ public static Action<T1,T2,T3,T4,T5,T6> CreateAction<T1,T2,T3,T4,T5,T6>(this ISh
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7> CreateAction<T1,T2,T3,T4,T5,T6,T7>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -416,7 +416,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7> CreateAction<T1,T2,T3,T4,T5,T6,T7>(th
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -464,7 +464,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8> CreateAction<T1,T2,T3,T4,T5,T6,T7,
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -512,7 +512,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9> CreateAction<T1,T2,T3,T4,T5,T6,
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -560,7 +560,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> CreateAction<T1,T2,T3,T4,T5
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -608,7 +608,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> CreateAction<T1,T2,T3,T
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -656,7 +656,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> CreateAction<T1,T2,
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -704,7 +704,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> CreateAction<T1
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -752,7 +752,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> CreateActio
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down Expand Up @@ -800,7 +800,7 @@ public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> CreateA
/// <param name="action">The action itself.</param>
public static Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>(this ISharedState sharedState, Action<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16> action)
{
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>(sharedState, null, null, action);
return CreateAction<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Cortex.Net/Api/ActionExtensions.generated.tt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Cortex.Net.Api
/// <param name="action">The action itself.</param>
public static Action<#=typeArgs#> CreateAction<#=typeArgs#>(this ISharedState sharedState, Action<#=typeArgs#> action)
{
return CreateAction<#=typeArgs#>(sharedState, null, null, action);
return CreateAction<#=typeArgs#>(sharedState, "<unnamed action>", null, action);
}

/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions src/Cortex.Net/Api/SharedStateObservableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,28 @@ public static IDictionary<TKey, TValue> Dictionary<TKey, TValue>(this ISharedSta

return new ObservableDictionary<TKey, TValue>(sharedState, enhancer, initialValues, name);
}

/// <summary>
/// Creates a computed value.
/// </summary>
/// <typeparam name="T">The type of the elements.</typeparam>
/// <param name="sharedState">The shared state to operate on.</param>
/// <param name="getter">The getter function to use.</param>
/// <param name="name">The name of the observable collection.</param>
/// <returns>The computed value.</returns>
public static IComputedValue<T> Computed<T>(this ISharedState sharedState, Func<T> getter, string name = null)
{
if (sharedState is null)
{
throw new ArgumentNullException(nameof(sharedState));
}

if (string.IsNullOrEmpty(name))
{
name = $"{nameof(ComputedValue<T>)}@{sharedState.GetUniqueId()}";
}

return new ComputedValue<T>(sharedState, new ComputedValueOptions<T>(getter, name));
}
}
}
4 changes: 2 additions & 2 deletions src/Cortex.Net/Core/ActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static partial class ActionExtensions
/// <param name="scope">The scope of the action.</param>
/// <param name="arguments">The arguments to the action.</param>
/// <returns>An <see cref="ActionRunInfo"/> instance containing the information on the currently running action.</returns>
private static ActionRunInfo StartAction(ISharedState sharedState, string actionName, object scope, object[] arguments)
internal static ActionRunInfo StartAction(ISharedState sharedState, string actionName, object scope, object[] arguments)
{
var notifySpy = !string.IsNullOrEmpty(actionName);
var previousDerivation = sharedState.StartUntracked();
Expand Down Expand Up @@ -74,7 +74,7 @@ private static ActionRunInfo StartAction(ISharedState sharedState, string action
/// Ends an action using the specified <see cref="ActionRunInfo"/> instance.
/// </summary>
/// <param name="actionRunInfo">The run info about the action.</param>
private static void EndAction(ActionRunInfo actionRunInfo)
internal static void EndAction(ActionRunInfo actionRunInfo)
{
if (actionRunInfo.SharedState.CurrentActionId != actionRunInfo.ActionId)
{
Expand Down
Loading

0 comments on commit 02c08ca

Please sign in to comment.