diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-24 12:53:26 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-24 12:53:26 -0600 |
| commit | 95c1a8f301745897e4dcd0f6b8367e6f85dd2080 (patch) | |
| tree | 0ea6f8acc0bc63ddf949cf2c12c45300ab149d21 | |
| parent | da928b0dbee3afd4042cd08ef45e6f03c41f47e0 (diff) | |
refactor: remove New()
| -rw-r--r-- | pkg/event/aggregator.go | 6 | ||||
| -rw-r--r-- | pkg/event/aggregator_test.go | 7 | ||||
| -rw-r--r-- | pkg/event/typed_aggregator.go | 8 |
3 files changed, 11 insertions, 10 deletions
diff --git a/pkg/event/aggregator.go b/pkg/event/aggregator.go index 0beaf86..996a550 100644 --- a/pkg/event/aggregator.go +++ b/pkg/event/aggregator.go @@ -6,12 +6,6 @@ type Aggregator struct { subscriptions map[Event][]Subscription } -func New() *Aggregator { - return x.New[*Aggregator]( - WithoutSubscriptions(), - ) -} - func WithoutSubscriptions() x.Option[*Aggregator] { return WithSubscriptions(map[Event][]Subscription{}) } diff --git a/pkg/event/aggregator_test.go b/pkg/event/aggregator_test.go index 7341bfd..bca4a5f 100644 --- a/pkg/event/aggregator_test.go +++ b/pkg/event/aggregator_test.go @@ -4,18 +4,19 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/xlgmokha/x/pkg/x" ) func TestAggregator(t *testing.T) { t.Run("Publish", func(t *testing.T) { t.Run("without any subscribers", func(t *testing.T) { - aggregator := New() + aggregator := x.New(WithoutSubscriptions()) aggregator.Publish("announcements.engineering", "Business, Business, Business... Numbers!") }) t.Run("with a single subscriber", func(t *testing.T) { - aggregator := New() + aggregator := x.New(WithoutSubscriptions()) called := false aggregator.Subscribe("announcement", func(message any) { @@ -29,7 +30,7 @@ func TestAggregator(t *testing.T) { }) t.Run("with multiple subscribers", func(t *testing.T) { - aggregator := New() + aggregator := x.New(WithoutSubscriptions()) called := map[int]bool{} aggregator.Subscribe("announcement", func(message any) { diff --git a/pkg/event/typed_aggregator.go b/pkg/event/typed_aggregator.go index 4932531..5572372 100644 --- a/pkg/event/typed_aggregator.go +++ b/pkg/event/typed_aggregator.go @@ -7,7 +7,13 @@ type TypedAggregator[T any] struct { } func NewAggregator[T any]() *TypedAggregator[T] { - return NewWith[T](x.New(WithoutSubscriptions())) + return x.New[*TypedAggregator[T]]( + WithAggregator[T]( + x.New( + WithoutSubscriptions(), + ), + ), + ) } func NewWith[T any](aggregator *Aggregator) *TypedAggregator[T] { |
