-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CouchTrackerSyncTests green. We can sync and get back WatchedShows
- Loading branch information
Pietro Caselani
committed
Jan 7, 2020
1 parent
f9feef0
commit ed6a099
Showing
20 changed files
with
8,448 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
protocol DataStruct {} | ||
|
||
extension DataStruct { | ||
func setValueOptional<T>(_ value: OptionalCopyValue<T>, _ defaultValue: T?) -> T? { | ||
switch value { | ||
case let .new(content): | ||
return content | ||
case .same: | ||
return defaultValue | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
func setValue<T>(_ value: CopyValue<T>, _ defaultValue: T) -> T { | ||
switch value { | ||
case let .new(content): | ||
return content | ||
case .same: | ||
return defaultValue | ||
} | ||
} | ||
} | ||
|
||
enum OptionalCopyValue<T> { | ||
case new(T) | ||
case same | ||
case `nil` | ||
} | ||
|
||
enum CopyValue<T> { | ||
case new(T) | ||
case same | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Given the following enum | ||
|
||
``` | ||
enum ViewState<T>: EnumClosures { | ||
case start(data: T) | ||
case loading | ||
case completed(count: Int, message: String) | ||
} | ||
``` | ||
|
||
will generate the following code | ||
|
||
``` | ||
extension ViewState { | ||
internal func onStart(_ fn: (T) -> Void) { | ||
guard case let .start(data) = self else { return } | ||
fn(data) | ||
} | ||
internal func onLoading(_ fn: () -> Void) { | ||
guard case .loading = self else { return } | ||
fn() | ||
} | ||
internal func onCompleted(_ fn: (Int, String) -> Void) { | ||
guard case let .completed(count, message) = self else { return } | ||
fn(count, message) | ||
} | ||
} | ||
``` | ||
*/ | ||
public protocol EnumClosures {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// See `EnumClosures` and `EnumProperties` | ||
public protocol EnumPoetry: EnumClosures, EnumProperties {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Given the following enum | ||
|
||
``` | ||
enum ViewState<T>: EnumProperties { | ||
case start(T) | ||
case loading | ||
case completed(Int, String) | ||
} | ||
``` | ||
|
||
will generate the following code | ||
|
||
``` | ||
extension ViewState { | ||
internal var isStart: Bool { | ||
guard case .start = self else { return false } | ||
return true | ||
} | ||
internal var isLoading: Bool { | ||
guard case .loading = self else { return false } | ||
return true | ||
} | ||
internal var isCompleted: Bool { | ||
guard case .completed = self else { return false } | ||
return true | ||
} | ||
|
||
internal var start: T? { | ||
guard case let .start(data) = self else { return nil } | ||
return (data) | ||
} | ||
internal var completed: (count: Int, message: String)? { | ||
guard case let .completed(count, message) = self else { return nil } | ||
return (count, message) | ||
} | ||
} | ||
``` | ||
*/ | ||
public protocol EnumProperties {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import TraktSwift | ||
|
||
public struct Episode: Hashable, Codable { | ||
public let ids: EpisodeIds | ||
public let showIds: ShowIds | ||
public let title: String? | ||
public let overview: String? | ||
public let number: Int | ||
public let season: Int | ||
public let firstAired: Date? | ||
public let absoluteNumber: Int? | ||
public let runtime: Int? | ||
public let rating: Double? | ||
public let votes: Int? | ||
|
||
public init(ids: EpisodeIds, showIds: ShowIds, title: String?, overview: String?, | ||
number: Int, season: Int, firstAired: Date?, absoluteNumber: Int?, | ||
runtime: Int?, rating: Double?, votes: Int?) { | ||
self.ids = ids | ||
self.showIds = showIds | ||
self.title = title | ||
self.overview = overview | ||
self.number = number | ||
self.season = season | ||
self.firstAired = firstAired | ||
self.absoluteNumber = absoluteNumber | ||
self.runtime = runtime | ||
self.rating = rating | ||
self.votes = votes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import TraktSwift | ||
|
||
public struct Show: Hashable, Codable { | ||
public let ids: ShowIds | ||
public let title: String? | ||
public let overview: String? | ||
public let network: String? | ||
public let genres: [Genre] | ||
public let status: Status? | ||
public let firstAired: Date? | ||
public let seasons: [WatchedSeason] | ||
|
||
public init(ids: ShowIds, title: String?, overview: String?, network: String?, | ||
genres: [Genre], status: Status?, firstAired: Date?, seasons: [WatchedSeason]) { | ||
self.ids = ids | ||
self.title = title | ||
self.overview = overview | ||
self.network = network | ||
self.genres = genres | ||
self.status = status | ||
self.firstAired = firstAired | ||
self.seasons = seasons | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public struct WatchedEpisode: Hashable, Codable { | ||
public let episode: Episode | ||
public let lastWatched: Date? | ||
|
||
public init(episode: Episode, lastWatched: Date?) { | ||
self.episode = episode | ||
self.lastWatched = lastWatched | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import TraktSwift | ||
|
||
public struct WatchedSeason: Hashable, Codable { | ||
public let showIds: ShowIds | ||
public let seasonIds: SeasonIds | ||
public let number: Int | ||
public let aired: Int? | ||
public let completed: Int? | ||
public let episodes: [WatchedEpisode] | ||
public let overview: String? | ||
public let title: String? | ||
public let firstAired: Date? | ||
public let network: String? | ||
|
||
public init(showIds: ShowIds, seasonIds: SeasonIds, number: Int, | ||
aired: Int?, completed: Int?, episodes: [WatchedEpisode], | ||
overview: String?, title: String?, firstAired: Date?, network: String?) { | ||
self.showIds = showIds | ||
self.seasonIds = seasonIds | ||
self.number = number | ||
self.aired = aired | ||
self.completed = completed | ||
self.episodes = episodes | ||
self.overview = overview | ||
self.title = title | ||
self.firstAired = firstAired | ||
self.network = network | ||
} | ||
} |
Oops, something went wrong.