-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathASTableNode+Rx.swift
More file actions
56 lines (47 loc) · 1.86 KB
/
ASTableNode+Rx.swift
File metadata and controls
56 lines (47 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// ASTableNode+Rx.swift
//
//
// Created by Dang Thai Son on 7/15/17.
// Copyright (c) 2017 RxSwiftCommunity. All rights reserved.
//
import Foundation
import AsyncDisplayKit
import RxSwift
import RxCocoa
public extension Reactive where Base: ASTableNode {
func items<DataSource: RxASTableDataSourceType & ASTableDataSource, O: ObservableType>(dataSource: DataSource)
-> (_ source: O)
-> Disposable where DataSource.Element == O.Element {
return { source in
let subscription = source
.subscribeProxyDataSource(ofObject: self.base, dataSource: dataSource, retainDataSource: true) { [weak tableNode = self.base] (_: RxASTableDataSourceProxy, event) -> Void in
guard let tableNode = tableNode else { return }
dataSource.tableNode(tableNode, observedEvent: event)
}
return Disposables.create {
subscription.dispose()
}
}
}
}
extension Reactive where Base: ASTableNode {
/**
Reactive wrapper for `dataSource`.
For more information take a look at `DelegateProxyType` protocol documentation.
*/
public var dataSource: DelegateProxy<ASTableNode, ASTableDataSource> {
return RxASTableDataSourceProxy.proxy(for: base)
}
/**
Installs data source as forwarding delegate on `rx.dataSource`.
Data source won't be retained.
It enables using normal delegate mechanism with reactive delegate mechanism.
- parameter dataSource: Data source object.
- returns: Disposable object that can be used to unbind the data source.
*/
public func setDataSource(_ dataSource: ASTableDataSource)
-> Disposable {
return RxASTableDataSourceProxy.installForwardDelegate(dataSource, retainDelegate: false, onProxyForObject: self.base)
}
}