updates to ev and webfinger
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jon Lundy
2023-05-29 09:48:20 -06:00
parent 7c4c1521fd
commit 5b9b436125
19 changed files with 559 additions and 57 deletions

View File

@@ -233,3 +233,33 @@ func (p *property[T]) SetEventMeta(x T) {
p.v = x
}
}
func AsEvent[T any](e T) Event {
return &asEvent[T]{payload: e}
}
type asEvent [T any] struct {
payload T
IsEvent
}
func (e asEvent[T]) Payload() T {
return e.payload
}
type AGG interface{ApplyEvent(...Event)}
func AsAggregate[T AGG](e T) Aggregate {
return &asAggregate[T]{payload: e}
}
type asAggregate [T AGG] struct {
payload T
IsAggregate
}
func (e *asAggregate[T]) Payload() T {
return e.payload
}
func (e *asAggregate[T]) ApplyEvent(lis ...Event) {
e.payload.ApplyEvent(lis...)
}

View File

@@ -55,3 +55,28 @@ func TestEventEncode(t *testing.T) {
is.Equal(lis[i], chk[i])
}
}
type exampleAgg struct{ value string }
func (a *exampleAgg) ApplyEvent(lis ...event.Event) {
for _, e := range lis {
switch e := e.(type) {
case interface{ Payload() exampleEvSetValue }:
a.value = e.Payload().value
}
}
}
type exampleEvSetValue struct{ value string }
func TestApplyEventGeneric(t *testing.T) {
payload := &exampleAgg{}
var agg = event.AsAggregate(payload)
agg.ApplyEvent(event.NewEvents(
event.AsEvent(exampleEvSetValue{"hello"}),
)...)
is := is.New(t)
is.Equal(payload.value, "hello")
}