Class SharedState
Holds the Shared state that all nodes of the Dependency Graph share.
Inheritance
Implements
Namespace: Cortex.Net
Assembly: Cortex.Net.dll
Syntax
public sealed class SharedState : object, ISharedState
Constructors
| Improve this Doc View SourceSharedState()
Initializes a new instance of the SharedState class.
Declaration
public SharedState()
SharedState(CortexConfiguration)
Initializes a new instance of the SharedState class.
Declaration
public SharedState(CortexConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
CortexConfiguration | configuration | The configuration to initialize SharedState instance with. |
Properties
| Improve this Doc View SourceAllowStateChanges
Gets a value indicating whether it is allowed to change observables at this point.
Declaration
public bool AllowStateChanges { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
AllowStateReads
Gets a value indicating whether it is allowed to read observables at this point.
Declaration
public bool AllowStateReads { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
ComputationDepth
Gets or sets the computation depth.
Declaration
public int ComputationDepth { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Configuration
Gets the configuration.
Declaration
public CortexConfiguration Configuration { get; }
Property Value
Type | Description |
---|---|
CortexConfiguration |
CurrentActionId
Gets or sets the Id of the Current Action.
Declaration
public int CurrentActionId { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Enhancers
Gets a list of enhancers on this SharedState.
Declaration
public IList<IEnhancer> Enhancers { get; }
Property Value
Type | Description |
---|---|
IList<IEnhancer> |
GlobalState
Gets a reference to the Global Shared State or throws an exception when the Shared State is configured to not allow Shared State.
Declaration
public static ISharedState GlobalState { get; }
Property Value
Type | Description |
---|---|
ISharedState |
InBatch
Gets a value indicating whether the Dependency Graph is in Batch mode.
Declaration
public bool InBatch { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsRunningReactions
Gets a value indicating whether this shared state is running reactions.
Declaration
public bool IsRunningReactions { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
NextActionId
Gets or sets the Id of the Next Action.
Declaration
public int NextActionId { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
PendingReactions
Gets a queue of pending reactions.
Declaration
public Queue<Reaction> PendingReactions { get; }
Property Value
Type | Description |
---|---|
Queue<Reaction> |
PendingUnobservations
Gets a queue of all pending Unobservations.
Declaration
public Queue<IObservable> PendingUnobservations { get; }
Property Value
Type | Description |
---|---|
Queue<IObservable> |
ReactionScheduler
Gets or sets the Scheduler function. The Scheduler function can call it's inner action to run the default reaction algorithm in Cortex.NET.
Declaration
public Action<Action> ReactionScheduler { get; set; }
Property Value
Type | Description |
---|---|
Action<Action> |
RunId
Gets the shared derivation RunId counter.
Declaration
public int RunId { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
ShouldInvoke
Gets a value indicating whether the action should be invoked on the original thread that created the context.
Declaration
public bool ShouldInvoke { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
SuppressReactionErrors
Gets or sets a value indicating whether to suppress reaction errors. Suppressing happens when an action is the root cause of reactions to fail further because of the incorrect state.
Declaration
public bool SuppressReactionErrors { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
TrackingDerivation
Gets the IDerivation instance that the shared state is currently tracking.
Declaration
public IDerivation TrackingDerivation { get; }
Property Value
Type | Description |
---|---|
IDerivation |
Methods
| Improve this Doc View SourceCreateAtom(String, Action, Action)
Creates a new Atom that references this shared Storage.
Declaration
public IAtom CreateAtom(string name = null, Action onBecomeObserved = null, Action onBecomeUnobserved = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name for this Atom. A unique name will be generated in case a name is not provided. |
Action | onBecomeObserved | An |
Action | onBecomeUnobserved | An |
Returns
Type | Description |
---|---|
IAtom | A new instance that implements IAtom. |
EndAllowStateChanges(Boolean)
End of a section where AllowStateChanges is modified.
Declaration
public void EndAllowStateChanges(bool previousAllowStateChanges)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | previousAllowStateChanges | The previous value to restore. |
EndAllowStateReads(Boolean)
End of a section where allowedStateReads is modified.
Declaration
public void EndAllowStateReads(bool previousAllowStateReads)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | previousAllowStateReads | The previous value to restore. |
EndBatch()
Ends a Batch.
Declaration
public void EndBatch()
Remarks
This method can be called multiple times but should always be balanced with an equal amount of StartBatch() calls.
EndTracking(IDerivation)
Ends tracking the current IDerivation instance and restores the previous derivation.
Declaration
public void EndTracking(IDerivation previousDerivation)
Parameters
Type | Name | Description |
---|---|---|
IDerivation | previousDerivation | The previous derivation. |
GetUniqueId()
Gets a unique Id that is incremented every time and identifies unique instances.
Declaration
public int GetUniqueId()
Returns
Type | Description |
---|---|
System.Int32 | The new unique Id. |
IncrementRunId()
Increments the RunId and returns the new value.
Declaration
public int IncrementRunId()
Returns
Type | Description |
---|---|
System.Int32 | The new RunId. |
OnSpy(Object, SpyEventArgs)
Triggers the Spy event handler with the specified event args.
Declaration
public void OnSpy(object sender, SpyEventArgs spyEventArgs)
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | The sender of the event. |
SpyEventArgs | spyEventArgs | The event arguments for the spy event. |
OnUnhandledReactionException(Reaction, UnhandledExceptionEventArgs)
Fires the UnhandledReactionException event.
Declaration
public void OnUnhandledReactionException(Reaction reaction, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
Parameters
Type | Name | Description |
---|---|---|
Reaction | reaction | The reaction that caused the unhandled exception. |
UnhandledExceptionEventArgs | unhandledExceptionEventArgs | The event arguments for the exception. |
ResolveState(ISharedState)
Resolves a shared state for Weaved objects.
Declaration
public static ISharedState ResolveState(ISharedState sharedState)
Parameters
Type | Name | Description |
---|---|---|
ISharedState | sharedState | The shared state. |
Returns
Type | Description |
---|---|
ISharedState | Shared state when found, otherwise throws an exception. |
RunReactions()
Runs reactions. This implementation will run the default Reaction Scheduler function.
Declaration
public void RunReactions()
SetAsyncLocalState(ISharedState)
Set the AsyncLocalSharedState.
Declaration
public static void SetAsyncLocalState(ISharedState sharedState)
Parameters
Type | Name | Description |
---|---|---|
ISharedState | sharedState | The Async Local Shared State. |
StartAllowStateChanges(Boolean)
Start of a section where AllowStateChanges is modified.
Declaration
public bool StartAllowStateChanges(bool allowStateChanges)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowStateChanges | Whether to allow State changes. |
Returns
Type | Description |
---|---|
System.Boolean | The previous value. |
StartAllowStateReads(Boolean)
Start of a section where allowedStateReads is modified.
Declaration
public bool StartAllowStateReads(bool allowStateReads)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowStateReads | Whether to allow State reads. |
Returns
Type | Description |
---|---|
System.Boolean | The previous value. |
StartBatch()
Starts a Batch.
Declaration
public void StartBatch()
Remarks
This method can be called multiple times but should always be balanced with an equal amount of EndBatch() calls.
StartTracking(IDerivation)
Starts tracking the IDerivation instance given as paramteter.
Declaration
public IDerivation StartTracking(IDerivation derivation)
Parameters
Type | Name | Description |
---|---|---|
IDerivation | derivation | The derivation to track. |
Returns
Type | Description |
---|---|
IDerivation | The prevous derivation. |
StartUntracked()
Starts an untracked part of a derviation.
Declaration
public IDerivation StartUntracked()
Returns
Type | Description |
---|---|
IDerivation | The current derivation to restore later. |
Events
| Improve this Doc View SourceSpyEvent
Spy event that fires when any observable attached to this Shared State reports a significant change. Can be used to implement a state inspection tool or something like react-dev-tools.
Declaration
public event EventHandler<SpyEventArgs> SpyEvent
Event Type
Type | Description |
---|---|
EventHandler<SpyEventArgs> |
UnhandledReactionException
Event that fires when a reaction produces an unhandled exception.
Declaration
public event EventHandler<UnhandledExceptionEventArgs> UnhandledReactionException
Event Type
Type | Description |
---|---|
EventHandler<UnhandledExceptionEventArgs> |