Last active
July 12, 2019 15:06
-
-
Save GeekTree0101/130247251949810a131e205dc15cffc7 to your computer and use it in GitHub Desktop.
Model - View - Intention (MVI)
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
struct User { | |
var id: String | |
var username: String | |
} | |
extension User: ServiceLogics { | |
static func loadUser(id: String) -> Promise<User> { ... } | |
static func loadUserFromDB(id: String) -> Promise<User> { ... } | |
} |
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
protocol UserListCellIntentLogics { | |
func didTapUser() | |
} | |
class UserListCellIntent: UserListCellIntentLogics { | |
weak var view: UserListCellNodeDisplayLogics? | |
weak var repository: UserListRepository? | |
func didTapUser() { | |
let user = User.loadUser(id: id) | |
user.then { | |
UserListCellViewState(user: $0) | |
} | |
.done { | |
view?.state($0) | |
} | |
user.then { | |
repository.replace(user: $0) | |
} | |
} | |
} |
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
protocol UserListCellNodeDisplayLogics { | |
func state(viewState: UserListCellViewState) | |
} | |
class UserListCellNode: ASCellNode { | |
var usernameTextNode = ASTextNode() | |
var intent: UserListCellIntentLogics = UserListCellIntent() | |
override init() { | |
super.init() | |
intent.view = self | |
} | |
func state(viewState: UserListCellViewState) { | |
usernameTextNode.attributedText = viewState.username.attributeText() | |
} | |
@objc func didTapUser() { | |
self.intent.didTapUser() | |
} | |
} |
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 UserListRepository { | |
var userSequence: [User] = [] | |
func append(user: User) { ... } | |
func delete(id: String) { ... } | |
func append(users: [User]) { ... } | |
func replace(user: User) { ... } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment