Skip to content

Commit 73d03c9

Browse files
committed
Add ASBindingObserver
1 parent a8b308f commit 73d03c9

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

RxTextureDataSources.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
57154BFF1F3B28B3008F0E38 /* ASBindingObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57154BFE1F3B28B3008F0E38 /* ASBindingObserver.swift */; };
1011
57826BA01F29477000FB0414 /* RxASCollectionReloadDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57826B9F1F29477000FB0414 /* RxASCollectionReloadDataSource.swift */; };
1112
57826BA21F29485500FB0414 /* RxASTableReloadDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57826BA11F29485500FB0414 /* RxASTableReloadDataSource.swift */; };
1213
57826BAA1F29491800FB0414 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57826BA91F29491800FB0414 /* AppDelegate.swift */; };
@@ -93,6 +94,7 @@
9394
35CD65171E60192300AF060B /* watchOS-Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "watchOS-Framework.xcconfig"; sourceTree = "<group>"; };
9495
35CD65181E60192300AF060B /* watchOS-StaticLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "watchOS-StaticLibrary.xcconfig"; sourceTree = "<group>"; };
9596
497271B10CB7AAE70BBDEAF0 /* Pods_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
97+
57154BFE1F3B28B3008F0E38 /* ASBindingObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASBindingObserver.swift; sourceTree = "<group>"; };
9698
57826B9F1F29477000FB0414 /* RxASCollectionReloadDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxASCollectionReloadDataSource.swift; sourceTree = "<group>"; };
9799
57826BA11F29485500FB0414 /* RxASTableReloadDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxASTableReloadDataSource.swift; sourceTree = "<group>"; };
98100
57826BA71F29491800FB0414 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -359,6 +361,7 @@
359361
children = (
360362
57E5632B1F290656002E825B /* RxHelpers.swift */,
361363
57E5632D1F29066F002E825B /* ASDelegateProxy.swift */,
364+
57154BFE1F3B28B3008F0E38 /* ASBindingObserver.swift */,
362365
);
363366
path = RxHelper;
364367
sourceTree = "<group>";
@@ -609,6 +612,7 @@
609612
57E563571F290FCD002E825B /* Array+Extensions.swift in Sources */,
610613
57E563491F290718002E825B /* RxASTableAnimatedDataSource.swift in Sources */,
611614
57E563481F290718002E825B /* ASTableSectionedDataSource.swift in Sources */,
615+
57154BFF1F3B28B3008F0E38 /* ASBindingObserver.swift in Sources */,
612616
57E5636A1F291A81002E825B /* ASCollectionNode+SectionViewType.swift in Sources */,
613617
57826BA21F29485500FB0414 /* RxASTableReloadDataSource.swift in Sources */,
614618
57E563651F291597002E825B /* RxASTableDelegateProxy.swift in Sources */,

Sources/DataSources/ASTableNode+Rx/RxASTableAnimatedDataSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ open class RxASTableAnimatedDataSource<S: AnimatableSectionModelType>: ASTableSe
2525
}
2626

2727
open func tableNode(_ tableNode: ASTableNode, observedEvent: RxSwift.Event<Element>) {
28-
UIBindingObserver(UIElement: self) { dataSource, newSections in
28+
ASBindingObserver(UIElement: self) { dataSource, newSections in
2929
#if DEBUG
3030
self._dataSourceBound = true
3131
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// ASBindingObserver.swift
3+
// RxTextureDataSources
4+
//
5+
// Created by Dang Thai Son on 8/9/17.
6+
// Copyright © 2017 RxSwiftCommunity. All rights reserved.
7+
//
8+
9+
#if !RX_NO_MODULE
10+
import RxSwift
11+
#endif
12+
13+
public class ASBindingObserver<UIElementType, Value> : ObserverType where UIElementType: AnyObject {
14+
public typealias E = Value
15+
16+
weak var UIElement: UIElementType?
17+
18+
let binding: (UIElementType, Value) -> Void
19+
20+
/// Initializes `ViewBindingObserver` using
21+
public init(UIElement: UIElementType, binding: @escaping (UIElementType, Value) -> Void) {
22+
self.UIElement = UIElement
23+
self.binding = binding
24+
}
25+
26+
/// Binds next element to owner view as described in `binding`.
27+
public func on(_ event: Event<Value>) {
28+
29+
switch event {
30+
case .next(let element):
31+
if let view = self.UIElement {
32+
binding(view, element)
33+
}
34+
case .error(let error):
35+
bindingErrorToInterface(error)
36+
case .completed:
37+
break
38+
}
39+
}
40+
41+
/// Erases type of observer.
42+
///
43+
/// - returns: type erased observer.
44+
public func asObserver() -> AnyObserver<Value> {
45+
return AnyObserver(eventHandler: on)
46+
}
47+
}

0 commit comments

Comments
 (0)