-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Updates based on DOs and DONTs (#429)
* update module Aggregate docs * Add Queries section * Add DDB article link * Add Light example * Remove Accumulator
- Loading branch information
Showing
6 changed files
with
97 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Domain.Tests.LightTests | ||
|
||
open Domain.Light | ||
open Swensen.Unquote | ||
|
||
type Case = Off | On | After3Cycles | ||
let establish = function | ||
| Off -> initial | ||
| On -> fold initial [| SwitchedOn |] | ||
| After3Cycles -> [| for _ in 1..3 do SwitchedOn; SwitchedOff |] |> fold initial | ||
|
||
let run cmd state = | ||
let events = decideSwitch cmd state | ||
events, fold state events | ||
|
||
let [<FsCheck.Xunit.Property>] props case cmd = | ||
let state = establish case | ||
let events, state = run cmd state | ||
match case, cmd with | ||
| Off, true -> events =! [| SwitchedOn |] | ||
| Off, false -> events =! [||] | ||
| On, true -> events =! [||] | ||
| On, false -> events =! [| SwitchedOff |] | ||
| After3Cycles, true -> events =! [| Broke |] | ||
| After3Cycles, false -> events =! [||] | ||
|
||
[||] =! decideSwitch cmd state // all commands are idempotent |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// By Jérémie Chassaing / @thinkb4coding | ||
/// https://github.com/dddeu/dddeu20-talks-jeremie-chassaing-functional-event-sourcing/blob/main/EventSourcing.fsx#L52-L84 | ||
module Domain.Light | ||
|
||
type Event = | ||
| SwitchedOn | ||
| SwitchedOff | ||
| Broke | ||
type State = | ||
| Working of CurrentState | ||
| Broken | ||
and CurrentState = { on: bool; remainingUses: int } | ||
let initial = Working { on = false; remainingUses = 3 } | ||
let private evolve s e = | ||
match s with | ||
| Broken -> s | ||
| Working s -> | ||
match e with | ||
| SwitchedOn -> Working { on = true; remainingUses = s.remainingUses - 1 } | ||
| SwitchedOff -> Working { s with on = false } | ||
| Broke -> Broken | ||
let fold = Array.fold evolve | ||
|
||
let decideSwitch (on: bool) s = [| | ||
match s with | ||
| Broken -> () | ||
| Working { on = true } -> | ||
if not on then | ||
SwitchedOff | ||
| Working { on = false; remainingUses = r } -> | ||
if on then | ||
if r = 0 then Broke | ||
else SwitchedOn |] |