Skip to content

Commit 9330b94

Browse files
committed
Merge branch 'master' of github.com:GeekTree0101/GTTexture-RxExtension
2 parents 3461e9b + dd8f68b commit 9330b94

20 files changed

Lines changed: 338 additions & 61 deletions

.travis.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
language: objective-c
22
osx_image: xcode9.1
33

4+
cache: cocoapods
5+
podfile: Example/Podfile
6+
7+
before_install:
8+
- pod install --repo-update --project-directory=Example
9+
10+
branches:
11+
only:
12+
- master
13+
414
script:
5-
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/GTTexture-RxExtension.xcworkspace -scheme GTTexture-RxExtension-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
6-
- pod lib lint
15+
- xcodebuild clean -workspace Example/GTTexture-RxExtension.xcworkspace -scheme GTTexture-RxExtension | xcpretty
16+
- xcodebuild build -sdk iphonesimulator -workspace Example/GTTexture-RxExtension.xcworkspace -scheme GTTexture-RxExtension CODE_SIGNING_REQUIRED=NO | xcpretty
17+

Example/GTTexture-RxExtension.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
1313
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
1414
95B109AB7AC68C78787AC9D9 /* Pods_GTTexture_RxExtension_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01237F39CD08F88DCFB4552C /* Pods_GTTexture_RxExtension_Tests.framework */; };
15+
9B8A890F20A02194000CEF86 /* ASBinderTestNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B8A890E20A02194000CEF86 /* ASBinderTestNode.swift */; };
1516
9BB6AC56209D7A38003DDE2A /* ASNetworkImageNode+RxExtensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BB6AC44209D725B003DDE2A /* ASNetworkImageNode+RxExtensionSpec.swift */; };
1617
9BB6AC57209D7A3B003DDE2A /* ASTextNode+RxExtensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BB6AC46209D726B003DDE2A /* ASTextNode+RxExtensionSpec.swift */; };
1718
9BB6AC58209D7A3D003DDE2A /* ASImageNode+RxExtensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BB6AC42209D724E003DDE2A /* ASImageNode+RxExtensionSpec.swift */; };
@@ -49,6 +50,7 @@
4950
6C4199A7267EB6A72A028AC3 /* Pods-GTTexture-RxExtension_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GTTexture-RxExtension_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-GTTexture-RxExtension_Tests/Pods-GTTexture-RxExtension_Tests.release.xcconfig"; sourceTree = "<group>"; };
5051
860A25685F324157C6CBA70F /* Pods-GTTexture-RxExtension_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GTTexture-RxExtension_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GTTexture-RxExtension_Tests/Pods-GTTexture-RxExtension_Tests.debug.xcconfig"; sourceTree = "<group>"; };
5152
95934C72A791E92FD8C7638B /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
53+
9B8A890E20A02194000CEF86 /* ASBinderTestNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ASBinderTestNode.swift; sourceTree = "<group>"; };
5254
9BB6AC3C209D7221003DDE2A /* ASButtonNode+RxExtensionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ASButtonNode+RxExtensionSpec.swift"; sourceTree = "<group>"; };
5355
9BB6AC3E209D7233003DDE2A /* ASControlNode+RxExtensionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ASControlNode+RxExtensionSpec.swift"; sourceTree = "<group>"; };
5456
9BB6AC42209D724E003DDE2A /* ASImageNode+RxExtensionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ASImageNode+RxExtensionSpec.swift"; sourceTree = "<group>"; };
@@ -185,6 +187,7 @@
185187
9BB6AC60209D8C6C003DDE2A /* ImageTestNode.swift */,
186188
9BB6AC66209D8CB3003DDE2A /* NetworkImageTestNode.swift */,
187189
9BB6AC6A209D8CD0003DDE2A /* TextTestNode.swift */,
190+
9B8A890E20A02194000CEF86 /* ASBinderTestNode.swift */,
188191
);
189192
name = Nodes;
190193
sourceTree = "<group>";
@@ -434,6 +437,7 @@
434437
files = (
435438
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
436439
9BB6AC5D209D8C35003DDE2A /* ButtonTestNode.swift in Sources */,
440+
9B8A890F20A02194000CEF86 /* ASBinderTestNode.swift in Sources */,
437441
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
438442
9BB6AC6B209D8CD0003DDE2A /* TextTestNode.swift in Sources */,
439443
9BB6AC61209D8C6C003DDE2A /* ImageTestNode.swift in Sources */,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// ASBinderTestNode.swift
3+
//
4+
// Created by Geektree0101.
5+
// Copyright(C) 2018 Geektree0101. All rights reserved.
6+
//
7+
8+
import Foundation
9+
import AsyncDisplayKit
10+
import GTTexture_RxExtension
11+
import RxSwift
12+
import RxCocoa
13+
14+
class ASBinderTestNode: ASDisplayNode {
15+
16+
let textNode = ASTextNode()
17+
let imageNode = ASNetworkImageNode()
18+
let disposeBag = DisposeBag()
19+
let url = URL(string: "https://koreaboo-cdn.storage.googleapis.com/2017/08/sana-1-1.jpg")
20+
21+
override init() {
22+
super.init()
23+
self.automaticallyManagesSubnodes = true
24+
25+
Observable.just(url)
26+
.bind(to: imageNode.rx.url, setNeedsLayout: self)
27+
.disposed(by: disposeBag)
28+
29+
Observable.just(Optional<String>("optional text"))
30+
.bind(to: textNode.rx.text(nil), setNeedsLayout: self)
31+
.disposed(by: disposeBag)
32+
}
33+
}

Example/GTTexture-RxExtension/ViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import UIKit
99
import AsyncDisplayKit
1010
import RxSwift
1111
import RxCocoa
12-
import GTTexture_RxExtension
1312

1413
class ViewController: ASViewController<ASDisplayNode> {
1514
let disposeBag = DisposeBag()

Example/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ target 'GTTexture-RxExtension_Example' do
66
target 'GTTexture-RxExtension_Tests' do
77
inherit! :search_paths
88

9-
pod 'Quick', '~> 1.2.0'
10-
pod 'Nimble', '~> 7.0.2'
9+
pod 'Quick'
10+
pod 'Nimble'
1111
pod 'RxTest', '~> 4.0'
1212
end
1313
end

Example/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ PODS:
3535

3636
DEPENDENCIES:
3737
- GTTexture-RxExtension (from `../`)
38-
- Nimble (~> 7.0.2)
39-
- Quick (~> 1.2.0)
38+
- Nimble
39+
- Quick
4040
- RxTest (~> 4.0)
4141

4242
EXTERNAL SOURCES:
@@ -55,6 +55,6 @@ SPEC CHECKSUMS:
5555
RxTest: e634f15fd2c2cd0e0120132ef7a4f7be69ad0393
5656
Texture: 7249074582daf75e524e59df5428b66b8e8db0e4
5757

58-
PODFILE CHECKSUM: 44b068eee2c6a4f13d221d7c065ec7cb448b279a
58+
PODFILE CHECKSUM: 68115f24e3cc3827d8759c972f6629a1789cec41
5959

6060
COCOAPODS: 1.3.1

GTTexture-RxExtension.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Pod::Spec.new do |s|
33
s.version = '1.1.0'
44
s.summary = 'Texture RxSwift Extension'
55

6-
s.description = 'Texture RxSwift Extension'
6+
s.description = 'Texture RxSwift Interactive Wrapper base on ASControlNode'
77

88
s.homepage = 'https://github.com/Geektree0101/GTTexture-RxExtension'
99
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
//
2+
// ASBinder.swift
3+
//
4+
// Created by Geektree0101.
5+
// Copyright(C) 2018 Geektree0101. All rights reserved.
6+
//
7+
8+
import AsyncDisplayKit
9+
import RxSwift
10+
import RxCocoa
11+
12+
public struct ASBinder<Value>: ASObserverType {
13+
public typealias E = Value
14+
15+
private let _binding: (Event<Value>, ASDisplayNode?) -> ()
16+
17+
public init<Target: AnyObject>(_ target: Target,
18+
scheduler: ImmediateSchedulerType = MainScheduler(),
19+
binding: @escaping (Target, Value) -> ()) {
20+
weak var weakTarget = target
21+
22+
_binding = { event, node in
23+
switch event {
24+
case .next(let element):
25+
_ = scheduler.schedule(element) { element in
26+
if let target = weakTarget {
27+
binding(target, element)
28+
29+
// set needs layout targeted node
30+
if let `node` = node {
31+
node.setNeedsLayout()
32+
}
33+
}
34+
return Disposables.create()
35+
}
36+
case .error(let error):
37+
#if DEBUG
38+
fatalError(error.localizedDescription)
39+
#else
40+
print(error)
41+
#endif
42+
case .completed:
43+
break
44+
}
45+
}
46+
}
47+
48+
public func on(_ event: Event<Value>, node: ASDisplayNode?) {
49+
_binding(event, node)
50+
}
51+
52+
public func on(_ event: Event<Value>) {
53+
_binding(event, nil)
54+
}
55+
}
56+
57+
public protocol ASObserverType: ObserverType {
58+
func on(_ event: Event<E>, node: ASDisplayNode?)
59+
}
60+
61+
extension ObservableType {
62+
public func bind<O>(to observer: O,
63+
setNeedsLayout node: ASDisplayNode? = nil)
64+
-> Disposable where O : ASObserverType, Self.E == O.E {
65+
return subscribe { event in
66+
switch event {
67+
case .next:
68+
observer.on(event, node: node)
69+
case .error(let error):
70+
#if DEBUG
71+
fatalError(error.localizedDescription)
72+
#else
73+
print(error)
74+
#endif
75+
case .completed:
76+
break
77+
}
78+
}
79+
}
80+
81+
public func bind<O: ASObserverType>(to observer: O,
82+
setNeedsLayout node: ASDisplayNode? = nil)
83+
-> Disposable where O.E == E? {
84+
return self.map { $0 }.subscribe { observerEvent in
85+
switch observerEvent {
86+
case .next:
87+
observer.on(observerEvent.map({ Optional<Self.E>($0) }),
88+
node: node)
89+
case .error(let error):
90+
#if DEBUG
91+
fatalError(error.localizedDescription)
92+
#else
93+
print(error)
94+
#endif
95+
case .completed:
96+
break
97+
}
98+
}
99+
}
100+
101+
public func bind(to relay: PublishRelay<E>,
102+
setNeedsLayout node: ASDisplayNode?) -> Disposable {
103+
return subscribe { e in
104+
switch e {
105+
case let .next(element):
106+
relay.accept(element)
107+
node?.setNeedsLayout()
108+
case let .error(error):
109+
let log = "Binding error to publish relay: \(error)"
110+
#if DEBUG
111+
fatalError(log)
112+
#else
113+
print(log)
114+
#endif
115+
case .completed:
116+
break
117+
}
118+
}
119+
}
120+
121+
public func bind(to relay: PublishRelay<E?>,
122+
setNeedsLayout node: ASDisplayNode? = nil) -> Disposable {
123+
return self.map { $0 as E? }
124+
.bind(to: relay, setNeedsLayout: node)
125+
}
126+
127+
public func bind(to relay: BehaviorRelay<E>,
128+
setNeedsLayout node: ASDisplayNode? = nil) -> Disposable {
129+
return subscribe { e in
130+
switch e {
131+
case let .next(element):
132+
relay.accept(element)
133+
node?.setNeedsLayout()
134+
case let .error(error):
135+
let log = "Binding error to behavior relay: \(error)"
136+
#if DEBUG
137+
fatalError(log)
138+
#else
139+
print(log)
140+
#endif
141+
case .completed:
142+
break
143+
}
144+
}
145+
}
146+
147+
public func bind(to relay: BehaviorRelay<E?>,
148+
setNeedsLayout node: ASDisplayNode? = nil) -> Disposable {
149+
return self.map { $0 as E? }
150+
.bind(to: relay, setNeedsLayout: node)
151+
}
152+
}

0 commit comments

Comments
 (0)