Skip to content

Commit

Permalink
Tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Jan 24, 2022
1 parent 7f1f76b commit 54d15da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
21 changes: 11 additions & 10 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,7 @@ elements you'll touch in a normal application are:
- [`type Decider`](https://github.com/jet/equinox/blob/master/src/Equinox/Decider.fs#L11) -
surface API one uses to `Transact` or `Query` against a specific stream's state
- [`type LoadOption` Discriminated Union](https://github.com/jet/equinox/blob/master/src/Equinox/Decider.fs#L59) -
used to specify optimization overrides to be applied when
`resolve` hydrates a `Decider`
used to specify optimization overrides to be applied when a `Decider`'s `Query` or `Transact` operations establishes the state of the stream

Its recommended to read the examples in conjunction with perusing the code in
order to see the relatively simple implementations that underlie the
Expand Down Expand Up @@ -1325,10 +1324,11 @@ let interpretMany fold interpreters (state : 'state) : 'state * 'event list =
type Service internal (resolve : CartId -> Equinox.Decider<Events.Event, Fold.State>) =
member _.Run(cartId, optimistic, commands : Command seq, ?prepare) : Async<Fold.State> =
let decider = resolve (cartId,if optimistic then Some Equinox.AllowStale else None)
decider.TransactAsync(fun state -> async {
let decider = resolve cartId
let opt = if optimistic then Equinox.AllowStale else Equinox.RequireLoad
decider.Transact(fun state -> async {
match prepare with None -> () | Some prep -> do! prep
return interpretMany Fold.fold (Seq.map interpret commands) state })
return interpretMany Fold.fold (Seq.map interpret commands) state }, opt)
```

<a name="accumulator"></a>
Expand Down Expand Up @@ -1368,7 +1368,7 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
interpret __.State |> accumulated.AddRange
/// Invoke an Async decision function, gathering the events (if any) that
/// it decides are necessary into the `Accumulated` sequence
member _.TransactAsync(interpret : 'state -> Async<'event list>) : Async<unit> = async {
member _.Transact(interpret : 'state -> Async<'event list>) : Async<unit> = async {
let! events = interpret __.State
accumulated.AddRange events }
/// Invoke a decision function, while also propagating a result yielded as
Expand All @@ -1379,21 +1379,22 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
result
/// Invoke a decision function, while also propagating a result yielded as
/// the fst of an (result, events) pair
member _.TransactAsync(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
member _.Transact(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
let! result, newEvents = decide __.State
accumulated.AddRange newEvents
return result }
type Service ... =
member _.Run(cartId, optimistic, commands : Command seq, ?prepare) : Async<Fold.State> =
let decider = resolve (cartId,if optimistic then Some Equinox.AllowStale else None)
decider.TransactAsync(fun state -> async {
let decider = resolve cartId
let opt = if optimistic then Some Equinox.AllowStale else Equinox.RequireLoad
decider.Transact(fun state -> async {
match prepare with None -> () | Some prep -> do! prep
let acc = Accumulator(Fold.fold, state)
for cmd in commands do
acc.Transact(interpret cmd)
return acc.State, acc.Accumulated
})
}, opt)
```

# Equinox Architectural Overview
Expand Down
9 changes: 5 additions & 4 deletions samples/Store/Domain/Cart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
member __.Transact(interpret : 'state -> 'event list) : unit =
interpret __.State |> accumulated.AddRange
/// Invoke an Async decision function, gathering the events (if any) that it decides are necessary into the `Accumulated` sequence
member __.TransactAsync(interpret : 'state -> Async<'event list>) : Async<unit> = async {
member __.Transact(interpret : 'state -> Async<'event list>) : Async<unit> = async {
let! events = interpret __.State
accumulated.AddRange events }
/// Invoke a decision function, while also propagating a result yielded as the fst of an (result, events) pair
Expand All @@ -121,7 +121,7 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
accumulated.AddRange newEvents
result
/// Invoke a decision function, while also propagating a result yielded as the fst of an (result, events) pair
member __.TransactAsync(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
member __.Transact(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
let! result, newEvents = decide __.State
accumulated.AddRange newEvents
return result }
Expand All @@ -142,13 +142,14 @@ type Service internal (resolve : CartId -> Equinox.Decider<Events.Event, Fold.St
#if ACCUMULATOR
let acc = Accumulator(Fold.fold, state)
for cmd in commands do
acc.Transact(interpret cmd, opt)
acc.Transact(interpret cmd)
return acc.State, acc.Accumulated }
#else
return interpretMany Fold.fold (Seq.map interpret commands) state }
#endif
let decider = resolve cartId
decider.Transact(interpret, (if optimistic then Equinox.AllowStale else Equinox.RequireLoad))
let opt = if optimistic then Equinox.AllowStale else Equinox.RequireLoad
decider.Transact(interpret, opt)

member __.ExecuteManyAsync(cartId, optimistic, commands : Command seq, ?prepare) : Async<unit> =
__.Run(cartId, optimistic, commands, ?prepare=prepare) |> Async.Ignore
Expand Down

0 comments on commit 54d15da

Please sign in to comment.