├── docs
├── _config.yml
└── img
│ └── logging.png
├── publish.cmd
├── src
├── StateInitialized.cs
├── AsyncAction.cs
├── IStateInitializer.cs
├── ILogicFlow.cs
├── Middleware
│ ├── IStoreMiddleware.cs
│ ├── LogicFlowsStoreMiddleware.cs
│ └── JsLoggingStoreMiddleware.cs
├── IStateFlow.cs
├── Rudder.sln
├── RudderExtensions.cs
├── StoreContainer.cs
├── Rudder.csproj
├── StateComponent.cs
├── Store.cs
├── RudderOptions.cs
└── Rudder.xml
├── LICENSE.txt
├── .gitignore
└── README.md
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-minimal
--------------------------------------------------------------------------------
/docs/img/logging.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kjeske/rudder/HEAD/docs/img/logging.png
--------------------------------------------------------------------------------
/publish.cmd:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | del src\bin\Release\*.nupkg
3 | dotnet pack src -c Release
4 | nuget push src\bin\Release\*.nupkg -Source https://api.nuget.org/v3/index.json
--------------------------------------------------------------------------------
/src/StateInitialized.cs:
--------------------------------------------------------------------------------
1 | namespace Rudder
2 | {
3 | ///
4 | /// Action dispatched after first render of the application
5 | ///
6 | public record StateInitialized;
7 | }
8 |
--------------------------------------------------------------------------------
/src/AsyncAction.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Rudder
4 | {
5 | ///
6 | /// Encapsulates a method that has a single parameter and returns a Task.
7 | ///
8 | /// Parameter type
9 | /// Parameter value
10 | public delegate Task AsyncAction(T1 arg1);
11 | }
12 |
--------------------------------------------------------------------------------
/src/IStateInitializer.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Rudder
4 | {
5 | ///
6 | /// Provides initial state for the application
7 | ///
8 | ///
9 | public interface IStateInitializer
10 | {
11 | ///
12 | /// Provides initial state for the application
13 | ///
14 | /// TState instance
15 | Task GetInitialStateAsync();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/ILogicFlow.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Rudder
4 | {
5 | ///
6 | /// Provides handler for an action that will execute the business logic and dispatch further action if needed
7 | ///
8 | public interface ILogicFlow
9 | {
10 | ///
11 | /// Handler for in incoming action for executing the business logic
12 | ///
13 | /// Action that is being currently processed
14 | Task OnNext(object action);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Middleware/IStoreMiddleware.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Rudder.Middleware
4 | {
5 | ///
6 | /// Provides a custom logic to execute when an action is being processed
7 | ///
8 | public interface IStoreMiddleware
9 | {
10 | ///
11 | /// Logic to execute when an action is being processed
12 | ///
13 | /// Action type
14 | /// Action instance
15 | Task Run(T action);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/IStateFlow.cs:
--------------------------------------------------------------------------------
1 | namespace Rudder
2 | {
3 | ///
4 | /// Provides a handler for an action that will change the state accordingly to the processing action
5 | ///
6 | ///
7 | public interface IStateFlow where TState : class
8 | {
9 | ///
10 | /// Handler for an action that will change the state accordingly to the processing action
11 | ///
12 | /// Current application state
13 | /// Processing action
14 | ///
15 | TState Handle(TState state, object actionValue);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Middleware/LogicFlowsStoreMiddleware.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 |
6 | namespace Rudder.Middleware
7 | {
8 | ///
9 | /// Provides logic flows execution
10 | ///
11 | public class LogicFlowsStoreMiddleware : IStoreMiddleware
12 | {
13 | private readonly Func> _flows;
14 |
15 | public LogicFlowsStoreMiddleware(Func> flows)
16 | {
17 | _flows = flows;
18 | }
19 |
20 | public async Task Run(T action) =>
21 | await Task.WhenAll(_flows().Select(flow => flow.OnNext(action)));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Middleware/JsLoggingStoreMiddleware.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.JSInterop;
2 |
3 | namespace Rudder.Middleware
4 | {
5 | ///
6 | /// Provides JavaScript logging for dispatched actions in a console
7 | ///
8 | public class JsLoggingStoreMiddleware : IStoreMiddleware
9 | {
10 | private readonly IJSRuntime _jsRuntime;
11 |
12 | public JsLoggingStoreMiddleware(IJSRuntime jsRuntime)
13 | {
14 | _jsRuntime = jsRuntime;
15 | }
16 |
17 | public async Task Run(TAction action)
18 | {
19 | try
20 | {
21 | await _jsRuntime.InvokeAsync