Compare commits
1 commit
eb9b4201e6
...
868f44e90e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
868f44e90e |
3 changed files with 12 additions and 23 deletions
11
.envrc
11
.envrc
|
|
@ -1,10 +1 @@
|
||||||
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
|
use flake . --no-pure-eval
|
||||||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
|
|
||||||
fi
|
|
||||||
|
|
||||||
watch_file flake.nix
|
|
||||||
watch_file flake.lock
|
|
||||||
if ! use flake . --no-pure-eval
|
|
||||||
then
|
|
||||||
echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
|
|
||||||
fi
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
package lu.foyer
|
package lu.foyer
|
||||||
|
|
||||||
import zio.*
|
import zio.*
|
||||||
import zio.schema.Schema
|
|
||||||
|
|
||||||
import lu.foyer.auth.UserInfo
|
|
||||||
|
|
||||||
final case class Entity[T](entityId: String, data: T, version: Long)
|
final case class Entity[T](entityId: String, data: T, version: Long)
|
||||||
final case class Event[T](entityId: String, data: T, eventId: String)
|
final case class Event[T](entityId: String, data: T, eventId: String)
|
||||||
|
|
@ -12,13 +9,3 @@ trait StateRepository[Data] extends Repository[Entity[Data], String]
|
||||||
trait EventRepository[Data] extends Repository[Event[Data], String]:
|
trait EventRepository[Data] extends Repository[Event[Data], String]:
|
||||||
def fetchOne(entityId: String, eventId: String): Task[Option[Event[Data]]]
|
def fetchOne(entityId: String, eventId: String): Task[Option[Event[Data]]]
|
||||||
def fetchMany(entityId: String, page: Page): Task[Paged[Event[Data]]]
|
def fetchMany(entityId: String, page: Page): Task[Paged[Event[Data]]]
|
||||||
|
|
||||||
trait Reducer[Event, State]:
|
|
||||||
def fromEmpty: PartialFunction[Event, State]
|
|
||||||
def fromState: PartialFunction[(State, Event), State]
|
|
||||||
|
|
||||||
def reduce(event: Event): Option[State] =
|
|
||||||
fromEmpty.lift(event)
|
|
||||||
|
|
||||||
def reduce(state: State, event: Event): Option[State] =
|
|
||||||
fromState.lift((state, event))
|
|
||||||
|
|
|
||||||
11
core/src/lu/foyer/Reducer.scala
Normal file
11
core/src/lu/foyer/Reducer.scala
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
package lu.foyer
|
||||||
|
|
||||||
|
trait Reducer[Event, State]:
|
||||||
|
def fromEmpty: PartialFunction[Event, State]
|
||||||
|
def fromState: PartialFunction[(State, Event), State]
|
||||||
|
|
||||||
|
def reduce(event: Event): Option[State] =
|
||||||
|
fromEmpty.lift(event)
|
||||||
|
|
||||||
|
def reduce(state: State, event: Event): Option[State] =
|
||||||
|
fromState.lift((state, event))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue