Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Last active January 8, 2020 11:33
Show Gist options
  • Save cipolleschi/a69fe7d5508311fef952755de0dd24f8 to your computer and use it in GitHub Desktop.
Save cipolleschi/a69fe7d5508311fef952755de0dd24f8 to your computer and use it in GitHub Desktop.
Proposal to remove the GlobalHak
import UIKit
// MARK: - Ramen State
public struct RamenState: AnyStateWithRamen, AnyLegacyState {
public var monetizationState: MonetizationState {
get { return monetizationState(from: self.monopolyState) }
}
var monopolyState: MonopolyState
}
public protocol AnyStateWithRamen {
var monetizationState: MonetizationState { get }
}
internal protocol AnyLegacyState {
var monopolyState: MonopolyState { get set }
}
internal extension RamenState {
func monetizationState(from monopolyState: MonopolyState) -> MonetizationState {
return MonetizationState(isReady: monopolyState.productFetched)
}
}
// MARK: - Monetization
public struct MonetizationState {
var isReady: Bool
}
// MARK: - Legacy
struct MonopolyState {
var productFetched: Bool
}
struct SetProductsFetched {
func updatedState(state: inout State) {
guard var legacyState = state as? AnyLegacyState else {
fatalError()
}
legacyState.monopolyState.productFetched = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment