-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
30 changed files
with
397 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
Source/Fluxor/DependencyInjection/InfoFactories/EffectMethodInfoFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,15 @@ | ||
using System; | ||
|
||
namespace Fluxor | ||
namespace Fluxor | ||
{ | ||
/// <summary> | ||
/// An interface that is injected into Blazor Components / pages for accessing | ||
/// the state of an <see cref="IFeature{TState}"/> | ||
/// </summary> | ||
public interface IState | ||
{ | ||
/// <summary> | ||
/// Event that is executed whenever the state changes | ||
/// </summary> | ||
event EventHandler StateChanged; | ||
} | ||
|
||
/// <summary> | ||
/// An interface that is injected into Blazor Components / pages for accessing | ||
/// the state of an <see cref="IFeature{TState}"/> | ||
/// </summary> | ||
/// <typeparam name="TState">The type of the state</typeparam> | ||
public interface IState<TState> : IState | ||
public interface IState<TState> : IStateChangedNotifier | ||
{ | ||
/// <summary> | ||
/// Returns the current state of the feature | ||
/// Returns the value selected from the feature state | ||
/// </summary> | ||
TState Value { get; } | ||
/// <summary> | ||
/// Event that is executed whenever the state changes | ||
/// </summary> | ||
new event EventHandler<TState> StateChanged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
|
||
namespace Fluxor | ||
{ | ||
/// <summary> | ||
/// An interface that is injected into Blazor Components / pages for accessing | ||
/// the a subset of state of an <see cref="IFeature{TState}"/> | ||
/// </summary> | ||
/// <typeparam name="TState">The type of the state</typeparam> | ||
/// <typeparam name="TValue">The type of the value selected from <see cref="TState"/></typeparam> | ||
public interface IStateSelection<TState, TValue> : IState<TValue> | ||
{ | ||
/// <summary> | ||
/// Identifies the part of the feature state to select | ||
/// </summary> | ||
/// <param name="selector">Function to select a value from the feature state</param> | ||
/// <param name="valueEquals"> | ||
/// Optional function used to check if two values are equal. | ||
/// Used to determine if an update to state needs | ||
/// to trigger a <see cref="IStateChangedNotifier.StateChanged"/> event | ||
/// </param> | ||
void Select( | ||
Func<TState, TValue> selector, | ||
Func<TValue, TValue, bool> valueEquals = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace Fluxor | ||
{ | ||
public interface IStateChangedNotifier | ||
{ | ||
/// <summary> | ||
/// Event that is executed whenever the observed value of the state changes | ||
/// </summary> | ||
event EventHandler StateChanged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,20 @@ | ||
using System; | ||
|
||
namespace Fluxor | ||
namespace Fluxor | ||
{ | ||
/// <summary> | ||
/// A class that is injected into Blazor components/pages that provides access | ||
/// to an <see cref="IFeature{TState}"/> state. | ||
/// </summary> | ||
/// <typeparam name="TState"></typeparam> | ||
public class State<TState> : IState<TState> | ||
public class State<TState> : StateSelection<TState, TState>, IStateSelection<TState, TState> | ||
{ | ||
private readonly IFeature<TState> Feature; | ||
|
||
/// <summary> | ||
/// Creates an instance of the state holder | ||
/// </summary> | ||
/// <param name="feature">The feature that contains the state</param> | ||
public State(IFeature<TState> feature) | ||
{ | ||
Feature = feature; | ||
} | ||
|
||
/// <see cref="IState{TState}.Value"/> | ||
public TState Value => Feature.State; | ||
|
||
/// <summary> | ||
/// Event that is executed whenever the state changes | ||
/// </summary> | ||
public event EventHandler<TState> StateChanged | ||
public State(IFeature<TState> feature) : base(feature) | ||
{ | ||
add { Feature.StateChanged += value; } | ||
remove { Feature.StateChanged -= value; } | ||
Select( | ||
x => x, // Select the state itself | ||
valueEquals: DefaultObjectReferenceEquals); // Compare by object reference | ||
} | ||
|
||
/// <summary> | ||
/// Event that is executed whenever the state changes | ||
/// </summary> | ||
event EventHandler IState.StateChanged | ||
{ | ||
add { (Feature as IFeature).StateChanged += value; } | ||
remove { (Feature as IFeature).StateChanged -= value; } | ||
} | ||
private static bool DefaultObjectReferenceEquals(TState x, TState y) => | ||
object.ReferenceEquals(x, y); | ||
} | ||
} |
Oops, something went wrong.