Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CompositeEventSourceBuilder #28

Merged
merged 2 commits into from
May 27, 2019

Conversation

JensAyton
Copy link
Contributor

@JensAyton JensAyton commented May 27, 2019

We currently have MergedEventSource to compose multiple event sources with the same event type, but it’s unergonomic because it takes an array of event sources, and you can’t construct an array of heterogeneous event sources due to limitations on protocols with associated types.

The current workaround is to explicitly wrap the members of the array in AnyEventSource, but explicit use of type erasure in clients is unpleasant.

Using a builder lets us take each individual event source as a generic parameter and handle the type erasure internally.

I called it CompositeEventSourceBuilder rather than MergedEventSourceBuilder by analogy to CompositeDisposable.

We currently have MergedEventSource to compose multiple event sources
with the same event type, but it’s unergonomic because it takes an array
of event sources, but you can’t construct an array of heterogeneous
event sources due to limitations on protocols with associated types.

The current workaround is to explicitly wrap the members of the array in
AnyEventSource, but explicit use of type erasure in clients is
unpleasant.

Using a builder lets us take each individual event source as a generic
parameter and handle the type erasure internally.

I called it CompositeEventSourceBuilder rather than MergedEventSource by
analogy to CompositeDisposable.
@JensAyton JensAyton force-pushed the composite-event-source-builder branch from 952166e to 6f680f4 Compare May 27, 2019 10:15
/// Builds an event source that composes all the event sources that have been added to the builder.
///
/// - Returns: An event source which represents the composition of the builder’s input event sources. The type
/// of this source is an implementation detail; consumers should avoid spelling it out if possible.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular, I’d like the return type to be some EventSource<.Event == Event>, but Swift 5.1 will only have unconstrained opaque types.

Copy link
Member

@pettermahlen pettermahlen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API and implementation look good to me!

@JensAyton
Copy link
Contributor Author

Now with unit tests.

In order to let the existing MergedEventSource tests run with MergedEventSource deprecated, I had to disable -warnings-as-errors in the test target. Unfortunately there is no finer-grained control for deprecation warnings in Swift.

@JensAyton JensAyton force-pushed the composite-event-source-builder branch from e662dea to 2755c9f Compare May 27, 2019 11:59
@JensAyton JensAyton force-pushed the composite-event-source-builder branch from 2755c9f to 7fb96ff Compare May 27, 2019 13:19
@codecov
Copy link

codecov bot commented May 27, 2019

Codecov Report

Merging #28 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #28      +/-   ##
==========================================
+ Coverage    96.9%   96.96%   +0.06%     
==========================================
  Files          35       36       +1     
  Lines         839      858      +19     
==========================================
+ Hits          813      832      +19     
  Misses         26       26
Impacted Files Coverage Δ
...usCore/Source/EventSources/MergedEventSource.swift 100% <ø> (ø) ⬆️
...rce/EventSources/CompositeEventSourceBuilder.swift 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23324ec...7fb96ff. Read the comment docs.

@jeppes jeppes merged commit a4bf64b into spotify:master May 27, 2019
@JensAyton JensAyton deleted the composite-event-source-builder branch May 27, 2019 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants