Skip to content

Commit

Permalink
change names of subscribe funcs to better understand what they do
Browse files Browse the repository at this point in the history
  • Loading branch information
hallgrenx committed May 30, 2020
1 parent 8b1ddf9 commit f42c3f4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions eventstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (e *EventStream) SubscribeAll(f func(e Event)) {
e.allEvents = append(e.allEvents, f)
}

// SubscribeAggregate bind the f function to be called on events on the aggregate type
func (e *EventStream) SubscribeAggregate(f func(e Event), aggregates ...aggregate) {
// SubscribeAggregateTypes bind the f function to be called on events on the aggregate type
func (e *EventStream) SubscribeAggregateTypes(f func(e Event), aggregates ...aggregate) {
for _, a := range aggregates {
aggregateType := reflect.TypeOf(a).Elem().Name()
if e.aggregateEvents[aggregateType] == nil {
Expand All @@ -69,8 +69,8 @@ func (e *EventStream) SubscribeAggregate(f func(e Event), aggregates ...aggregat
}
}

// SubscribeSpecific bind the f function to be called on specific events
func (e *EventStream) SubscribeSpecific(f func(e Event), events ...interface{}) {
// SubscribeSpecificEvents bind the f function to be called on specific events
func (e *EventStream) SubscribeSpecificEvents(f func(e Event), events ...interface{}) {
// subscribe to specified events
for _, event := range events {
t := reflect.TypeOf(event)
Expand Down
26 changes: 13 additions & 13 deletions eventstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func TestAll(t *testing.T) {
}
}

func TestSpecific(t *testing.T) {
func TestSubscribeOneEvent(t *testing.T) {
var streamEvent *eventsourcing.Event
e := eventsourcing.NewEventStream()
f := func(e eventsourcing.Event) {
streamEvent = &e
}
e.SubscribeSpecific(f, &AnEvent{})
e.SubscribeSpecificEvents(f, &AnEvent{})
e.Update([]eventsourcing.Event{event})

if streamEvent == nil {
Expand All @@ -63,13 +63,13 @@ func TestSpecific(t *testing.T) {
}
}

func TestSubscribeAggregate(t *testing.T) {
func TestSubscribeAggregateType(t *testing.T) {
var streamEvent *eventsourcing.Event
e := eventsourcing.NewEventStream()
f := func(e eventsourcing.Event) {
streamEvent = &e
}
e.SubscribeAggregate(f, &AnAggregate{}, &AnotherAggregate{})
e.SubscribeAggregateTypes(f, &AnAggregate{}, &AnotherAggregate{})

// update with event from the AnAggregate aggregate
e.Update([]eventsourcing.Event{event})
Expand All @@ -87,13 +87,13 @@ func TestSubscribeAggregate(t *testing.T) {
}
}

func TestManySpecific(t *testing.T) {
func TestSubscribeToManyEvents(t *testing.T) {
var streamEvents []*eventsourcing.Event
e := eventsourcing.NewEventStream()
f := func(e eventsourcing.Event) {
streamEvents = append(streamEvents, &e)
}
e.SubscribeSpecific(f, &AnEvent{}, &AnotherEvent{})
e.SubscribeSpecificEvents(f, &AnEvent{}, &AnotherEvent{})
e.Update([]eventsourcing.Event{event})
e.Update([]eventsourcing.Event{otherEvent})

Expand Down Expand Up @@ -123,7 +123,7 @@ func TestUpdateNoneSubscribedEvent(t *testing.T) {
f := func(e eventsourcing.Event) {
streamEvent = &e
}
e.SubscribeSpecific(f, &AnotherEvent{})
e.SubscribeSpecificEvents(f, &AnotherEvent{})
e.Update([]eventsourcing.Event{event})

if streamEvent != nil {
Expand Down Expand Up @@ -154,11 +154,11 @@ func TestManySubscribers(t *testing.T) {
f5 := func(e eventsourcing.Event) {
streamEvent5 = append(streamEvent5, e)
}
e.SubscribeSpecific(f1, &AnotherEvent{})
e.SubscribeSpecific(f2, &AnotherEvent{}, &AnEvent{})
e.SubscribeSpecific(f3, &AnEvent{})
e.SubscribeSpecificEvents(f1, &AnotherEvent{})
e.SubscribeSpecificEvents(f2, &AnotherEvent{}, &AnEvent{})
e.SubscribeSpecificEvents(f3, &AnEvent{})
e.SubscribeAll(f4)
e.SubscribeAggregate(f5, &AnAggregate{})
e.SubscribeAggregateTypes(f5, &AnAggregate{})

e.Update([]eventsourcing.Event{event})

Expand Down Expand Up @@ -197,8 +197,8 @@ func TestParallelUpdates(t *testing.T) {
f3 := func(e eventsourcing.Event) {
streamEvent = append(streamEvent, e)
}
e.SubscribeSpecific(f1, &AnEvent{})
e.SubscribeSpecific(f2, &AnotherEvent{})
e.SubscribeSpecificEvents(f1, &AnEvent{})
e.SubscribeSpecificEvents(f2, &AnotherEvent{})
e.SubscribeAll(f3)

wg := sync.WaitGroup{}
Expand Down
12 changes: 6 additions & 6 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ func (r *Repository) SubscribeAll(f func(e Event)) {
r.eventStream.SubscribeAll(f)
}

// SubscribeSpecific binds the input func f to be called when supplied events are saved.
func (r *Repository) SubscribeSpecific(f func(e Event), events ...interface{}) {
r.eventStream.SubscribeSpecific(f, events...)
// SubscribeSpecificEvents binds the input func f to be called when supplied events are saved.
func (r *Repository) SubscribeSpecificEvents(f func(e Event), events ...interface{}) {
r.eventStream.SubscribeSpecificEvents(f, events...)
}

// SubscribeAggregate binds the input func f to be called on all events bound to supplied aggregates
func (r *Repository) SubscribeAggregate(f func(e Event), aggregates ...aggregate) {
r.eventStream.SubscribeAggregate(f, aggregates...)
// SubscribeAggregateType binds the input func f to be called on all events bound to supplied aggregates
func (r *Repository) SubscribeAggregateType(f func(e Event), aggregates ...aggregate) {
r.eventStream.SubscribeAggregateTypes(f, aggregates...)
}
4 changes: 2 additions & 2 deletions repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestSubscriptionSpecific(t *testing.T) {
serializer := json.New()
serializer.Register(&Person{}, &Born{}, &AgedOneYear{})
repo := eventsourcing.NewRepository(memory.Create(serializer), nil)
repo.SubscribeSpecific(f, &Born{}, &AgedOneYear{})
repo.SubscribeSpecificEvents(f, &Born{}, &AgedOneYear{})

person, err := CreatePerson("kalle")
if err != nil {
Expand All @@ -172,7 +172,7 @@ func TestSubscriptionAggregate(t *testing.T) {
serializer := json.New()
serializer.Register(&Person{}, &Born{}, &AgedOneYear{})
repo := eventsourcing.NewRepository(memory.Create(serializer), nil)
repo.SubscribeAggregate(f, &Person{})
repo.SubscribeAggregateType(f, &Person{})

person, err := CreatePerson("kalle")
if err != nil {
Expand Down

0 comments on commit f42c3f4

Please sign in to comment.