Skip to content

Commit

Permalink
Per review: rename 'M' generic type to 'Model' for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-at-kickstarter committed Feb 13, 2024
1 parent b8a246c commit 0f87f10
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions KsApi/Service+RequestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import ReactiveSwift
extension Service {
private static let session = URLSession(configuration: .default)

func request<M: Decodable>(_ route: Route)
-> SignalProducer<M, ErrorEnvelope> {
func request<Model: Decodable>(_ route: Route)
-> SignalProducer<Model, ErrorEnvelope> {
let properties = route.requestProperties

guard let URL = URL(string: properties.path, relativeTo: self.serverConfig.apiBaseUrl as URL) else {
Expand All @@ -25,7 +25,7 @@ extension Service {
.flatMap(self.decodeModelToSignal)
}

func request<M: Decodable>(_ route: Route) -> AnyPublisher<M, ErrorEnvelope> {
func request<Model: Decodable>(_ route: Route) -> AnyPublisher<Model, ErrorEnvelope> {
let properties = route.requestProperties

guard let URL = URL(string: properties.path, relativeTo: self.serverConfig.apiBaseUrl as URL) else {
Expand All @@ -41,8 +41,8 @@ extension Service {
).handle_combine_dataResponse(service: self)
}

func requestPaginationDecodable<M: Decodable>(_ paginationUrl: String)
-> SignalProducer<M, ErrorEnvelope> {
func requestPaginationDecodable<Model: Decodable>(_ paginationUrl: String)
-> SignalProducer<Model, ErrorEnvelope> {
guard let paginationUrl = URL(string: paginationUrl) else {
return .init(error: .invalidPaginationUrl)
}
Expand All @@ -52,8 +52,8 @@ extension Service {
.flatMap(self.decodeModelToSignal)
}

func requestPaginationDecodable<M: Decodable>(_ paginationUrl: String)
-> AnyPublisher<M, ErrorEnvelope> {
func requestPaginationDecodable<Model: Decodable>(_ paginationUrl: String)
-> AnyPublisher<Model, ErrorEnvelope> {
guard let paginationUrl = URL(string: paginationUrl) else {
fatalError("Invalid pagination URL \(paginationUrl)")
}
Expand All @@ -65,10 +65,11 @@ extension Service {
}

extension Publisher where Output == Data, Failure == ErrorEnvelope {
func handle_combine_dataResponse<M: Decodable>(service: Service) -> AnyPublisher<M, ErrorEnvelope> {
func handle_combine_dataResponse<Model: Decodable>(service: Service) -> AnyPublisher<Model, ErrorEnvelope> {
return self
.tryMap { data in
let result: Result<M?, ErrorEnvelope> = service.decodeModelToResult(data: data, ofType: M.self)
let result: Result<Model?, ErrorEnvelope> = service
.decodeModelToResult(data: data, ofType: Model.self)

switch result {
case let .success(value):
Expand Down

0 comments on commit 0f87f10

Please sign in to comment.