Last active
July 21, 2019 23:57
-
-
Save GeekTree0101/1d270244607b17440453b6f3a6e52b9c to your computer and use it in GitHub Desktop.
Geek
This file contains hidden or 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
class CellNode { | |
struct State { | |
var id: Int | |
var title: String? | |
var isLike: Bool | |
} | |
public var state: State? | |
weak var action: Action? | |
public func update(_ state: State) { | |
} | |
} |
This file contains hidden or 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
class Action { | |
func fetch(_ request: UseCase.Feed.Request) -> Promise<UseCase.Feed.Response> { ... } | |
} |
This file contains hidden or 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
class State { | |
struct FeedState { | |
var items: [Item] | |
var isPagingEnded: Bool | |
} | |
struct Cell { | |
var id: Int | |
var title: String? | |
var isLike: Bool | |
} | |
func feedState(_ response: UseCase.Feed.Response, oldState: State.Feed) -> Promise<State.Feed> { ... } | |
} |
This file contains hidden or 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
enum UseCase { | |
enum Like { | |
struct Request { | |
var id: Int | |
var isLike: Bool | |
} | |
struct Response { | |
var item: Item | |
} | |
} | |
enum Feed { | |
struct Request { | |
enum Scope { | |
case reload | |
case loadMore | |
} | |
var scope: Scope | |
} | |
struct Response { | |
var items: [Item] | |
var hasNextPage: Bool | |
} | |
} | |
} |
This file contains hidden or 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
class ViewController { | |
private var state: State! | |
private var action: Action! | |
public var viewState: State.Feed? | |
public func update(_ state: State.Feed) { | |
} | |
@objc func reload() { | |
let request = UseCase.Feed.Request.init(scope: .reload) | |
intent.fetch(request) | |
.then { state.feedState($0, oldState: self.state) } | |
.done { [unowned self] newState in | |
self.update(newState) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment