Skip to content

Commit

Permalink
Remove snapshot tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Dec 24, 2018
1 parent a38a90c commit 19b9173
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
9 changes: 6 additions & 3 deletions samples/Infrastructure/Services.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ type ServiceBuilder(storageConfig, handlerLog) =

member __.CreateFavoritesService() =
let codec = genCodec<Domain.Favorites.Events.Event>()
let fold, initial, snapshot = Domain.Favorites.Folds.fold, Domain.Favorites.Folds.initial, Domain.Favorites.Folds.snapshot
let fold, initial = Domain.Favorites.Folds.fold, Domain.Favorites.Folds.initial
let snapshot = Domain.Favorites.Folds.isOrigin,Domain.Favorites.Folds.compact
Backend.Favorites.Service(handlerLog, resolver.Resolve(codec,fold,initial,snapshot))

member __.CreateSaveForLaterService() =
let codec = genCodec<Domain.SavedForLater.Events.Event>()
let fold, initial, snapshot = Domain.SavedForLater.Folds.fold, Domain.SavedForLater.Folds.initial, Domain.SavedForLater.Folds.snapshot
let fold, initial = Domain.SavedForLater.Folds.fold, Domain.SavedForLater.Folds.initial
let snapshot = Domain.SavedForLater.Folds.isOrigin,Domain.SavedForLater.Folds.compact
Backend.SavedForLater.Service(handlerLog, resolver.Resolve(codec,fold,initial,snapshot), maxSavedItems=50, maxAttempts=3)

member __.CreateTodosService() =
let codec = genCodec<TodoBackend.Events.Event>()
let fold, initial, snapshot = TodoBackend.Folds.fold, TodoBackend.Folds.initial, TodoBackend.Folds.snapshot
let fold, initial = TodoBackend.Folds.fold, TodoBackend.Folds.initial
let snapshot = TodoBackend.Folds.isOrigin, TodoBackend.Folds.compact
TodoBackend.Service(handlerLog, resolver.Resolve(codec,fold,initial,snapshot))

let register (services : IServiceCollection, storageConfig, handlerLog) =
Expand Down
2 changes: 1 addition & 1 deletion samples/Store/Domain/Cart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module Folds =
| Events.ItemWaiveReturnsChanged e -> updateItems (List.map (function i when i.skuId = e.skuId -> { i with returnsWaived = e.waived } | i -> i))
let fold state = Seq.fold evolve state
let isOrigin = function Events.Compacted _ -> true | _ -> false
let snapshot = isOrigin, State.toSnapshot >> Events.Compacted
let compact = State.toSnapshot >> Events.Compacted
type Context = { time: System.DateTime; requestId : RequestId }
type Command =
| AddItem of Context * SkuId * quantity: int
Expand Down
2 changes: 1 addition & 1 deletion samples/Store/Domain/Favorites.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Folds =
for e in events do evolve s e
s.AsState()
let isOrigin = function Events.Compacted _ -> true | _ -> false
let snapshot = isOrigin, fun state -> Events.Compacted { net = state }
let compact state = Events.Compacted { net = state }

type Command =
| Favorite of date : System.DateTimeOffset * skuIds : SkuId list
Expand Down
6 changes: 2 additions & 4 deletions samples/Store/Domain/SavedForLater.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ module Folds =
let proposedEventsWouldExceedLimit maxSavedItems events state =
let newState = fold state events
Array.length newState > maxSavedItems
let snapshot =
let isOrigin = function Compacted _ -> true | _ -> false
let generate state = Events.Compacted { items = state }
isOrigin, generate
let isOrigin = function Compacted _ -> true | _ -> false
let compact state = Events.Compacted { items = state }

module Commands =
type Command =
Expand Down
3 changes: 2 additions & 1 deletion samples/Store/Integration/CartIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ open Swensen.Unquote

#nowarn "1182" // From hereon in, we may have some 'unused' privates (the tests)

let fold, initial, snapshot = Domain.Cart.Folds.fold, Domain.Cart.Folds.initial, Domain.Cart.Folds.snapshot
let fold, initial = Domain.Cart.Folds.fold, Domain.Cart.Folds.initial
let snapshot = Domain.Cart.Folds.isOrigin, Domain.Cart.Folds.compact

let createMemoryStore () =
new VolatileStore ()
Expand Down
3 changes: 2 additions & 1 deletion samples/Store/Integration/FavoritesIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ open Swensen.Unquote

#nowarn "1182" // From hereon in, we may have some 'unused' privates (the tests)

let fold, initial, snapshot = Domain.Favorites.Folds.fold, Domain.Favorites.Folds.initial, Domain.Favorites.Folds.snapshot
let fold, initial = Domain.Favorites.Folds.fold, Domain.Favorites.Folds.initial
let snapshot = Domain.Favorites.Folds.isOrigin, Domain.Favorites.Folds.compact

let createMemoryStore () =
new VolatileStore()
Expand Down
2 changes: 1 addition & 1 deletion samples/TodoBackend/TodosService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Folds =
| Compacted items -> { s with items = List.ofArray items }
let fold state = Seq.fold evolve state
let isOrigin = function Events.Cleared | Events.Compacted _ -> true | _ -> false
let snapshot = isOrigin, fun state -> Compacted (Array.ofList state.items)
let compact state = Compacted (Array.ofList state.items)

type Command = Add of Todo | Update of Todo | Delete of id: int | Clear

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ let genCodec<'Union when 'Union :> TypeShape.UnionContract.IUnionContract>() =
Equinox.UnionCodec.JsonUtf8.Create<'Union>(serializationSettings)

module Cart =
let fold, initial, snapshot = Domain.Cart.Folds.fold, Domain.Cart.Folds.initial, Domain.Cart.Folds.snapshot
let fold, initial = Domain.Cart.Folds.fold, Domain.Cart.Folds.initial
let snapshot = Domain.Cart.Folds.isOrigin, Domain.Cart.Folds.compact
let codec = genCodec<Domain.Cart.Events.Event>()
let createServiceWithoutOptimization log gateway =
Backend.Cart.Service(log, GesResolver(gateway, codec, fold, initial).Resolve)
Expand Down

0 comments on commit 19b9173

Please sign in to comment.