Skip to content

Instantly share code, notes, and snippets.

View GeekTree0101's full-sized avatar
🚀

David Ha (小河) GeekTree0101

🚀
View GitHub Profile
@GeekTree0101
GeekTree0101 / DisplayCellNodeCASE_A.swift
Last active July 12, 2019 03:00
CleanSwift Example
class DisplayCellNode: ASCellNode {
// UI
let buttonNode = ASButtonNode()
// Props
weak var interactor: InteractorLogics!
private var presenter: DisplayCellPresenter = .init()
override func didLoad() {
class TestViewController {
let userInputView = InputView()
let displayOutputView: OutputView()
func bind() {
let state = Presenter.shared.state(type: OutputViewState.self, id: 1)
state.map { $0.title }.bind(to: displayOutputView.rx.title).disposed(by: bag)
}
}
@GeekTree0101
GeekTree0101 / RxCellNode.swift
Created July 7, 2019 12:55
Reactive CellNode
class ReactiveTestCellNode: ASCellNode {
public var viewState: ActionRelay<State> = .init()
func state() {
viewState.map { $0.title }
.distinguishUntilChanged()
.bind(to: titleNode.rx.title, setNeedsLayout: self)
.disposed(by: disposeBag)
}
@GeekTree0101
GeekTree0101 / AnimalInteractor.swift
Last active July 7, 2019 12:33
RxVIP inspired by Cycle.js Composable
protocol AnimalFeedInputLogics {
// 피드 메커니즘에 대한 비즈니스 로직만 수행할 수 있게 뷰컨으로 부터 이벤트를 받는 로직
var loadAnimalItem: PublishRelay<NextPage> { get } // Load more animation cell items
}
protocol AnimalCatCellInputLogics {
// 오직 고양이 셀로 부터 이벤트를 받는 로직
var didTapFollow: PublishRelay<Int> { get } // Int: Cat identifier
}
class Cell: ASCellNode {
let messageCountNode = ASButtonNode()
let likeCountNode = ASButtonNode()
func engageAreaLayoutSpec() -> ASLayoutSpec {
let stackLayout = ASStackLayoutSpec(children: [message....like])
return ASInsetLayoutSpec(insets: .init(top: 0, left: .inf, bottom: 0, right: 0, child: stackLayout)
}
}
class CellNode: ASCellNode {
let contentNode = ASDisplayNode()
override init() {
super.init()
self.ASM = true
self.contentNode.ASM = true
/*
Interactor의 input과 output에 대한 RxTest진행
어떠한 Request 이벤트 발생시 기대하는 Response 이벤트를 받는지?
Worker는 Stub으로 생성하여 Interactor에 주입
*/
class InteractorTests: XCTestCase {
var interactor: Interactor!
var disposeBag: DisposeBag!
@GeekTree0101
GeekTree0101 / RxVIP.swift
Last active May 25, 2019 14:50
RxVIP Interactor High Cohesion Issue Solve Example
struct MonkeyModel {
struct Request {
}
struct Response {
}
protocol MonkeyInteractorLogic: class {
var request: PublishRelay<MonkeyModel.Request> { get set }
}
class MonkeyInteractor: MonkeyInteractorLogic {
var presenter: MonkeyPresenterLogic? {
get {
@GeekTree0101
GeekTree0101 / test.swift
Last active May 22, 2019 04:52
RxVIP Sample
// Interactor
import UIKit
import RxSwift
import RxCocoa
protocol UserInteractorInputLogic {
var input: PublishRelay<UserModels.Model.Request> { get }
}