-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathASCollectionNode+rx.swift
More file actions
55 lines (46 loc) · 1.94 KB
/
Copy pathASCollectionNode+rx.swift
File metadata and controls
55 lines (46 loc) · 1.94 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
//
// ASCollectionNode+Rx.swift
// RxASDataSources
//
// Created by Dang Thai Son on 7/27/17.
// Copyright (c) 2017 RxSwiftCommunity. All rights reserved.
//
import AsyncDisplayKit
import RxSwift
import RxCocoa
public extension Reactive where Base: ASCollectionNode {
func items<DataSource: RxASCollectionDataSourceType & ASCollectionDataSource, 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 collectionNode = self.base] (_: RxASCollectionDataSourceProxy, event) -> Void in
guard let collectionNode = collectionNode else { return }
dataSource.collectionNode(collectionNode, observedEvent: event)
}
return Disposables.create {
subscription.dispose()
}
}
}
}
public extension Reactive where Base: ASCollectionNode {
/**
Reactive wrapper for `dataSource`.
For more information take a look at `DelegateProxyType` protocol documentation.
*/
var dataSource: DelegateProxy<ASCollectionNode, ASCollectionDataSource> {
return RxASCollectionDataSourceProxy.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.
*/
func setDataSource(_ dataSource: ASCollectionDataSource)
-> Disposable {
return RxASCollectionDataSourceProxy.installForwardDelegate(dataSource, retainDelegate: false, onProxyForObject: self.base)
}
}