Predictable state container for F# applications.
redux-fsharp is a Redux-like implementation of the unidirectional data flow architecture in F#.
If you want to add this package to your project, execute the following command:
dotnet add package redux-fsharp
If you want to build this library on your machine, execute the following commands:
git clone https://github.com/galassie/redux-fsharp.git
cd redux-fsharp
dotnet build
If you want to run the tests, execute the following command:
dotnet test
Required:
- Install Docker for your system
Build a Docker image called redux-fsharp
. This will work without any local .NET Core installation.
docker build -t redux-fsharp .
Use the following to instantiate a Docker container from the redux-fsharp
image and run the tests inside:
docker run --rm redux-fsharp dotnet test
type State = { CurrentValue: int }
type IncrementAction = { Amount: int }
type DecrementAction = { Amount: int }
type Actions =
| Increment of IncrementAction
| Decrement of DecrementAction
let incrementDecrementReducer state action =
match action with
| Increment { Amount = amount } -> { state with CurrentValue = state.CurrentValue + amount }
| Decrement { Amount = amount } -> { state with CurrentValue = state.CurrentValue - amount }
let consoleLogSubscriber state =
printfn "Current value: %d" state.CurrentValue
[<EntryPoint>]
let main argv =
let store = createStore incrementDecrementReducer { CurrentValue = 0 } id
let unsubscribe = store.Subscribe(consoleLogSubscriber)
store.Dispatch (Increment { Amount = 1 }) |> ignore
store.Dispatch (Increment { Amount = 2 }) |> ignore
store.Dispatch (Decrement { Amount = 1 }) |> ignore
unsubscribe() |> ignore
store.Dispatch (Decrement { Amount = 1 }) |> ignore
let lastState = store.GetState()
printfn "Expected Current value should be 1"
printfn "Actual Current value is %d" lastState.CurrentValue
0 // return an integer exit code
Code contributions are more than welcome! 😻
Please commit any pull requests against the master
branch.
If you find any issue, please report it!
This project is licensed under The MIT License (MIT).
Author: Enrico Galassi