Skip to content

Instantly share code, notes, and snippets.

@ahernandezlopez
Last active October 23, 2017 11:50
Show Gist options
  • Select an option

  • Save ahernandezlopez/0bc1af4398b231f91ef8db82a57652e6 to your computer and use it in GitHub Desktop.

Select an option

Save ahernandezlopez/0bc1af4398b231f91ef8db82a57652e6 to your computer and use it in GitHub Desktop.
Example of implementation of Domain Events in Swift. The snippet illustrates Domain Events in a Service with RxSwift
protocol ListingService: class {
var events: Observable<ListingServiceEvent> { get }
func filteredEvents(listing: Listing) -> Observable<ListingServiceEvent>
func create(params: ListingServiceCreateParams,
completion: ((Result<Listing, ListingServiceCreateError>) -> ())?)
func update(listing: Listing,
params: ListingServiceUpdateParams,
completion: ((Result<Listing, ListingServiceUpdateError>) -> ())?)
func delete(listing: Listing,
completion: ((Result<Listing, ListingServiceDeleteError>) -> ())?)
}
enum ListingServiceEvent {
case create(listing: Listing)
case update(listing: Listing)
case delete(listing: Listing)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment