forked from mercari/Mew
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
192 additions
and
1 deletion.
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
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,13 @@ | ||
// | ||
// EnvironmentRequest.swift | ||
// Mew | ||
// | ||
// Created by Shun Usami on 2019/06/26. | ||
// Copyright © 2019 Mercari. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol EnvironmentRequest { | ||
associatedtype EnvironmentResponse | ||
} |
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,103 @@ | ||
// | ||
// ViewControllerRequest.swift | ||
// Mew | ||
// | ||
// Created by Shun Usami on 2019/06/26. | ||
// Copyright © 2019 Mercari. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
// Instantiatable | ||
public protocol ViewControllerRequest: EnvironmentRequest where EnvironmentResponse == ViewControllerResponse { | ||
associatedtype Input | ||
associatedtype EnvironmentResponse = ViewControllerResponse | ||
|
||
var inputValue: Input { get } | ||
} | ||
|
||
extension ViewControllerRequest { | ||
public func response<V>(for type: V.Type, environment: V.Environment) | ||
-> ViewControllerResponse | ||
where V: UIViewController, | ||
V: Instantiatable, | ||
V.Input == Input { | ||
let viewController = V(with: inputValue, environment: environment) | ||
return ViewControllerResponse(viewController: viewController) | ||
} | ||
} | ||
|
||
// Injectable | ||
public protocol InjectableViewControllerRequest: EnvironmentRequest where EnvironmentResponse == InjectableViewControllerResponse<Input> { | ||
associatedtype Input | ||
associatedtype EnvironmentResponse = InjectableViewControllerResponse<Input> | ||
|
||
var inputValue: Input { get } | ||
} | ||
|
||
extension InjectableViewControllerRequest { | ||
public func response<V>(for type: V.Type, environment: V.Environment) | ||
-> InjectableViewControllerResponse<Input> | ||
where V: UIViewController, | ||
V: Instantiatable, | ||
V: Injectable, | ||
V.Input == Input { | ||
let viewController = V(with: inputValue, environment: environment) | ||
return InjectableViewControllerResponse( | ||
viewController: viewController, | ||
input: viewController.input | ||
) | ||
} | ||
} | ||
|
||
// Emittable | ||
public protocol EmittableViewControllerRequest: EnvironmentRequest where EnvironmentResponse == EmittableViewControllerResponse<Output> { | ||
associatedtype Input | ||
associatedtype Output | ||
associatedtype EnvironmentResponse = EmittableViewControllerResponse<Output> | ||
|
||
var inputValue: Input { get } | ||
} | ||
|
||
extension EmittableViewControllerRequest { | ||
public func response<V>(for type: V.Type, environment: V.Environment) | ||
-> EmittableViewControllerResponse<Output> | ||
where V: UIViewController, | ||
V: Instantiatable, | ||
V: Emittable, | ||
V.Input == Input, | ||
V.Output == Output { | ||
let viewController = V(with: inputValue, environment: environment) | ||
return EmittableViewControllerResponse( | ||
viewController: viewController, | ||
output: viewController.output | ||
) | ||
} | ||
} | ||
|
||
// Interactable | ||
public protocol InteractableViewControllerRequest: EnvironmentRequest where EnvironmentResponse == InteractableViewControllerResponse<Input, Output> { | ||
associatedtype Input | ||
associatedtype Output | ||
associatedtype EnvironmentResponse = InteractableViewControllerResponse<Input, Output> | ||
|
||
var inputValue: Input { get } | ||
} | ||
|
||
extension InteractableViewControllerRequest { | ||
public func response<V>(for type: V.Type, environment: V.Environment) | ||
-> InteractableViewControllerResponse<Input, Output> | ||
where V: UIViewController, | ||
V: Instantiatable, | ||
V: Interactable, | ||
V.Input == Input, | ||
V.Output == Output { | ||
let viewController = V(with: inputValue, environment: environment) | ||
return InteractableViewControllerResponse( | ||
viewController: viewController, | ||
input: viewController.input, | ||
output: viewController.output | ||
) | ||
} | ||
} |
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,54 @@ | ||
// | ||
// ViewControllerResponse.swift | ||
// Mew | ||
// | ||
// Created by Shun Usami on 2019/06/26. | ||
// Copyright © 2019 Mercari. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
public final class ViewControllerResponse { | ||
public let viewController: UIViewController | ||
|
||
public init(viewController: UIViewController) { | ||
self.viewController = viewController | ||
} | ||
} | ||
|
||
public final class InjectableViewControllerResponse<Input> { | ||
public let viewController: UIViewController | ||
public let input: (Input) -> Void | ||
|
||
public init(viewController: UIViewController, | ||
input: @escaping (Input) -> Void) { | ||
self.viewController = viewController | ||
self.input = input | ||
} | ||
} | ||
|
||
public final class EmittableViewControllerResponse<Output> { | ||
public let viewController: UIViewController | ||
public let output: (((Output) -> Void)?) -> Void | ||
|
||
public init(viewController: UIViewController, | ||
output: @escaping (((Output) -> Void)?) -> Void) { | ||
self.viewController = viewController | ||
self.output = output | ||
} | ||
} | ||
|
||
public final class InteractableViewControllerResponse<Input, Output> { | ||
public let viewController: UIViewController | ||
public let input: (Input) -> Void | ||
public let output: (((Output) -> Void)?) -> Void | ||
|
||
public init(viewController: UIViewController, | ||
input: @escaping (Input) -> Void, | ||
output: @escaping (((Output) -> Void)?) -> Void) { | ||
self.viewController = viewController | ||
self.input = input | ||
self.output = output | ||
} | ||
} |