Skip to content

Commit d791bda

Browse files
authored
Add FeatureAttribute.DebuggerBrowsable property to exclude features from ReduxDevTools serialization (Fixes #541) (#546)
* Exclude features with DebugBrowsable = false
1 parent 14e4dcd commit d791bda

File tree

7 files changed

+19
-5
lines changed

7 files changed

+19
-5
lines changed

Docs/releases.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Releases
22

3+
## New in 6.8
4+
* Added DebuggerBrowsable property to FeatureAttribute to prevent state being sent to ReduxDevTools ([#541](https://github.com/mrpmorris/Fluxor/issues/541))
5+
36
## New in 6.7
47
* Fix StoreInitialize error ([#535](https://github.com/mrpmorris/Fluxor/issues/535))
58
* Fix NullReferenceException when using ReduxDevTools ([#543](https://github.com/mrpmorris/Fluxor/issues/543))

Source/Lib/Fluxor.Blazor.Web.ReduxDevTools/Internal/ReduxDevToolsMiddleware.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ public override void AfterDispatch(object action)
8383
private IDictionary<string, object> GetState()
8484
{
8585
var state = new Dictionary<string, object>();
86-
foreach (IFeature feature in Store.Features.Values.OrderBy(x => x.GetName()))
86+
var serializableFeatures = Store.Features.Values.Where(x => x.DebuggerBrowsable);
87+
foreach (IFeature feature in serializableFeatures.OrderBy(x => x.GetName()))
8788
state[feature.GetName()] = feature.GetState();
8889
return state;
8990
}

Source/Lib/Fluxor/DependencyInjection/Wrappers/FeatureStateWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ internal class FeatureStateWrapper<TState> : Feature<TState>
77
private readonly string Name;
88
private readonly Func<object> CreateInitialStateFunc;
99

10-
public FeatureStateWrapper(
11-
FeatureStateInfo info)
10+
public FeatureStateWrapper(FeatureStateInfo info)
1211
{
1312
Name = info.FeatureStateAttribute.Name ?? typeof(TState).FullName;
1413
MaximumStateChangedNotificationsPerSecond = info.FeatureStateAttribute.MaximumStateChangedNotificationsPerSecond;
14+
DebuggerBrowsable = info.FeatureStateAttribute.DebuggerBrowsable;
1515
CreateInitialStateFunc = info.CreateInitialStateFunc;
1616
}
1717

Source/Lib/Fluxor/Feature.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public abstract class Feature<TState> : IFeature<TState>
1717
/// <see cref="IFeature.GetState"/>
1818
public virtual object GetState() => State;
1919

20+
/// <see cref="IFeature.DebuggerBrowsable"/>
21+
public virtual bool DebuggerBrowsable { get; set; }
22+
2023
/// <see cref="IFeature.RestoreState(object)"/>
2124
public virtual void RestoreState(object value) => State = (TState)value;
2225

Source/Lib/Fluxor/FeatureStateAttribute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public class FeatureStateAttribute : Attribute
77
{
88
public string Name { get; set; }
99
public string CreateInitialStateMethodName { get; set; }
10+
public bool DebuggerBrowsable { get; set; } = true;
1011
public byte MaximumStateChangedNotificationsPerSecond { get; set; }
1112
}

Source/Lib/Fluxor/IFeature.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ public interface IFeature
1414
/// <returns>The unique name of the feature</returns>
1515
string GetName();
1616

17+
/// <summary>
18+
/// Gets a value indicating whether the property should be visible
19+
/// in any attached debugger (e.g. ReduxDevTools).
20+
/// </summary>
21+
bool DebuggerBrowsable { get; }
22+
1723
/// <summary>
1824
/// If greater than 0, the feature will not execute state changes
1925
/// more often than this many times per second. Additional notifications
20-
/// will be surpressed, and observers will be notified of the latest
26+
/// will be suppressed, and observers will be notified of the latest
2127
/// state when the time window has elapsed to allow another notification.
2228
/// </summary>
2329
byte MaximumStateChangedNotificationsPerSecond { get; set; }

Source/Tutorials/02-Blazor/02D-ReduxDevToolsTutorial/ReduxDevToolsTutorial/Client/Store/CounterUseCase/CounterState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace FluxorBlazorWeb.ReduxDevToolsTutorial.Client.Store.CounterUseCase
44
{
5-
[FeatureState(Name = "Counter")]
5+
[FeatureState(Name = "Counter", DebuggerBrowsable = false)]
66
public class CounterState
77
{
88
public int ClickCount { get; }

0 commit comments

Comments
 (0)