XStatelessCompiler 1.0.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Framework 4.7.2
This package targets .NET Framework 4.7.2. The package is compatible with this framework or higher.
dotnet add package XStatelessCompiler --version 1.0.0
NuGet\Install-Package XStatelessCompiler -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XStatelessCompiler" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XStatelessCompiler --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: XStatelessCompiler, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XStatelessCompiler as a Cake Addin #addin nuget:?package=XStatelessCompiler&version=1.0.0 // Install XStatelessCompiler as a Cake Tool #tool nuget:?package=XStatelessCompiler&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
XStatelessCompiler
XState JSON state machine to Stateless compiler
Features
- OnEntry and OnExit effects
- Guarded and unguarded transitions
- Always transitions
- Context support
- Customizable state and context management
Available for
Usage
//Read XState json
var json = File.ReadAllText("xstate_machine.json");
//Compile
var compiler = new XStateCompiler(json);
var machine = compiler.Compile();
//Fire events
machine.RaiseEvent("START");
//Access state
var stateName = machine.State.Name;
Defining effects and context properties
var machine = compiler.Compile();
//Initialize context property
machine.Context["retries"] = true;
//Define effects
machine.SetEffect("increment", (context, e) => ++context["retries"]);
Using custom context and state management
//Create state and context store
var stateStore = new MemoryStateStore(initialState: new("initial"));
var contextStore = new MemoryContextStore();
//Initialize state machine with custom state and context stores
var machine = XStateMachine
.Create(stateStore)
.WithContext(contextStore);
var compiler = new XStateCompiler(json);
var machine = compiler.CompileFrom(machine);
Create custom state stores by extending BaseStateStore
public class MemoryStateStore : BaseStateStore
{
private XState _currentState;
protected override Func<XState> GetState { get; set; }
protected override Action<XState> SetState { get; set; }
public MemoryStateStore(XState initialState)
{
_currentState = initialState;
//Override SetState and GetState
SetState = (state) => _currentState = state;
GetState = () => _currentState;
}
}
Create custom context stores by extending BaseContextStore
public class MemoryContextStore : BaseContextStore
{
private readonly Dictionary<string, dynamic> _context = new();
protected override Func<string, dynamic> GetContext { get; set; }
protected override Action<string, dynamic> SetContext { get; set; }
public MemoryContextStore()
{
//Override SetContext and GetContext
SetContext = (key, value) => _context[key] = value;
GetContext = (key) => _context[key];
}
}
License
Copyright (c) 2023 Marco
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.7.2
- Microsoft.CSharp (>= 4.7.0)
- Stateless (>= 5.13.0)
- System.Text.Json (>= 7.0.2)
-
net6.0
- Microsoft.CSharp (>= 4.7.0)
- Stateless (>= 5.13.0)
- System.Text.Json (>= 7.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 184 | 5/27/2023 |
Initial release