Skip to content

Commit

Permalink
Bump to v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekTree0101 committed Aug 15, 2018
1 parent 63fc89a commit 4d85c26
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 216 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ PODS:
- RxSwift (~> 4)
- RxCocoa (4.2.0):
- RxSwift (~> 4.0)
- RxCocoa-Texture (2.0.0):
- RxCocoa-Texture (2.0.1):
- RxCocoa (~> 4.0)
- RxSwift (~> 4.0)
- Texture (= 2.6)
Expand Down Expand Up @@ -73,7 +73,7 @@ SPEC CHECKSUMS:
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
RxAlamofire: 87a9c588541210cc3e4a1f843ccc3ecf3eb98b31
RxCocoa: 0b54909c902e1e581212a03e690bbd94032d8baa
RxCocoa-Texture: 221b9d89b9e11f1fd3a833bac15222f1ff63eb70
RxCocoa-Texture: 2b9ae072430b9e58848e924ccc786c49422105d7
RxSwift: 99e10317ddfcc7fbe01356aafd118fde4a0be104
RxTest: 8da864c0ee47534f586ff18fb0c7e5b2f1fe5023
Texture: 7249074582daf75e524e59df5428b66b8e8db0e4
Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/RxCocoa-Texture.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

395 changes: 203 additions & 192 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Example/RxCocoa-Texture.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
9B0E163E210DADB70013EC86 /* ImageTestNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B0E1637210DADB60013EC86 /* ImageTestNode.swift */; };
9B0E163F210DADB70013EC86 /* ASBinderTestNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B0E1638210DADB70013EC86 /* ASBinderTestNode.swift */; };
9B0E1642210DADCF0013EC86 /* RepositoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B0E1641210DADCE0013EC86 /* RepositoryViewModel.swift */; };
9B6C23932124EB4200129E2F /* RepositoryViewModel2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B6C23922124EB4200129E2F /* RepositoryViewModel2.swift */; };
9BE3DFE3211E780600816FD9 /* ImageDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE3DFE2211E780500816FD9 /* ImageDownloader.swift */; };
C2B9E94A4FCBBCFCA86BBE1B /* Pods_RxCocoa_Texture_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30C467A356AD9535ACE740C9 /* Pods_RxCocoa_Texture_Tests.framework */; };
F77E2B9F7CE27BC62474DD2B /* Pods_RxCocoa_Texture_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B64F85DE41A757B8E1C3E68C /* Pods_RxCocoa_Texture_Example.framework */; };
Expand Down Expand Up @@ -78,6 +79,7 @@
9B0E1637210DADB60013EC86 /* ImageTestNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageTestNode.swift; sourceTree = "<group>"; };
9B0E1638210DADB70013EC86 /* ASBinderTestNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ASBinderTestNode.swift; sourceTree = "<group>"; };
9B0E1641210DADCE0013EC86 /* RepositoryViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryViewModel.swift; sourceTree = "<group>"; };
9B6C23922124EB4200129E2F /* RepositoryViewModel2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RepositoryViewModel2.swift; sourceTree = "<group>"; };
9BE3DFE2211E780500816FD9 /* ImageDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageDownloader.swift; sourceTree = "<group>"; };
9E1C79DA561D40B89763472E /* Pods-RxCocoa-Texture_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxCocoa-Texture_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RxCocoa-Texture_Tests/Pods-RxCocoa-Texture_Tests.debug.xcconfig"; sourceTree = "<group>"; };
A700DE1AE94F129E06542938 /* Pods-RxCocoa-Texture_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxCocoa-Texture_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-RxCocoa-Texture_Example/Pods-RxCocoa-Texture_Example.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -259,6 +261,7 @@
isa = PBXGroup;
children = (
9B0E1641210DADCE0013EC86 /* RepositoryViewModel.swift */,
9B6C23922124EB4200129E2F /* RepositoryViewModel2.swift */,
);
name = viewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -479,6 +482,7 @@
buildActionMask = 2147483647;
files = (
9B0E1630210DAD9D0013EC86 /* Network.swift in Sources */,
9B6C23932124EB4200129E2F /* RepositoryViewModel2.swift in Sources */,
9B0E162A210DAD890013EC86 /* Repository.swift in Sources */,
9B0E1626210DAD7B0013EC86 /* Decoder+extension.swift in Sources */,
9B0E161D210DAD550013EC86 /* RepositoryViewController.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Example/RxCocoa-Texture/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds) // create UIwindow
let viewController = RepositoryViewController2()
let viewController = RepositoryViewController()
let navigationController =
UINavigationController(rootViewController: viewController)
if let window = window {
Expand Down
6 changes: 0 additions & 6 deletions Example/RxCocoa-Texture/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,3 @@ class Repository: Decodable {
isForked = repo.isForked
}
}

extension Repository: ASRenderModelProtocol {
var renderModelIdentifier: ASRenderModelIdentifier {
return .init(id, type: type(of: self))
}
}
8 changes: 6 additions & 2 deletions Example/RxCocoa-Texture/RepositoryListCellNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,33 @@ class RepositoryListCellNode: ASCellNode {
print("DEBUG* deallocate \(id)")
}

init(viewModel: RepositoryViewModel) {
init(viewModel: RepositoryViewModel2) {
self.id = viewModel.id
super.init()
self.selectionStyle = .none
self.backgroundColor = .white
self.automaticallyManagesSubnodes = true

viewModel.profileURL
.bind(to: userProfileNode.rx.url)
.bind(to: userProfileNode.rx.url,
directlyBind: true)
.disposed(by: disposeBag)

viewModel.username
.bind(to: usernameNode.rx.text(Node.usernameAttributes),
directlyBind: true,
setNeedsLayout: self)
.disposed(by: disposeBag)

viewModel.desc
.bind(to: descriptionNode.rx.text(Node.descAttributes),
directlyBind: true,
setNeedsLayout: self)
.disposed(by: disposeBag)

viewModel.status
.bind(to: statusNode.rx.text(Node.statusAttributes),
directlyBind: true,
setNeedsLayout: self)
.disposed(by: disposeBag)

Expand Down
4 changes: 2 additions & 2 deletions Example/RxCocoa-Texture/RepositoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import RxCocoa

class RepositoryViewController: ASViewController<ASTableNode> {

private var items: [RepositoryViewModel] = []
private var items: [RepositoryViewModel2] = []
private var context = ASBatchContext()

let disposeBag = DisposeBag()
Expand Down Expand Up @@ -43,7 +43,7 @@ class RepositoryViewController: ASViewController<ASTableNode> {
_ = RepoService.loadRepository(params: [.since(since)])
.delay(0.5, scheduler: MainScheduler.asyncInstance)
.subscribeOn(ConcurrentDispatchQueueScheduler(qos: .default))
.map { $0.map { RepositoryViewModel(repository: $0) } }
.map { $0.map { RepositoryViewModel2(repository: $0) } }
.observeOn(MainScheduler.instance)
.subscribe(onSuccess: { [weak self] items in
guard let `self` = self else { return }
Expand Down
91 changes: 91 additions & 0 deletions Example/RxCocoa-Texture/RepositoryViewModel2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import Foundation
import RxSwift
import RxCocoa

class RepositoryViewModel2 {

// @INPUT
let updateRepository = PublishRelay<Repository>()
let updateUsername = PublishRelay<String?>()
let updateDescription = PublishRelay<String?>()
let updateProfileImage = PublishRelay<URL?>()

// @OUTPUT
var username = BehaviorRelay<String?>(value: nil)
var profileURL = BehaviorRelay<URL?>(value: nil)
var desc = BehaviorRelay<String?>(value: nil)
var status = BehaviorRelay<String?>(value: nil)

let id: Int
let disposeBag = DisposeBag()

deinit {
RepoProvider.release(id: id)
}

init(repository: Repository) {
self.id = repository.id

RepoProvider.addAndUpdate(repository)

let repoObserver = RepoProvider.observable(id: id)
.asObservable()
.share(replay: 1, scope: .whileConnected)

repoObserver
.map { $0?.user?.username }
.bind(to: username)
.disposed(by: disposeBag)

repoObserver
.map { $0?.user?.profileURL }
.bind(to: profileURL)
.disposed(by: disposeBag)

repoObserver
.map { $0?.desc }
.bind(to: desc)
.disposed(by: disposeBag)

repoObserver
.map { item -> String? in
var statusArray: [String] = []
if let isForked = item?.isForked, isForked {
statusArray.append("Forked")
}

if let isPrivate = item?.isPrivate, isPrivate {
statusArray.append("Private")
}

return statusArray.isEmpty ? nil: statusArray.joined(separator: " · ")
}.bind(to: status)
.disposed(by: disposeBag)

self.updateRepository.subscribe(onNext: { newRepo in
RepoProvider.update(newRepo)
}).disposed(by: disposeBag)

updateUsername.withLatestFrom(repoObserver) { ($0, $1) }
.subscribe(onNext: { text, repo in
guard let repo = repo else { return }
repo.user?.username = text ?? ""
RepoProvider.update(repo)
}).disposed(by: disposeBag)

updateDescription.withLatestFrom(repoObserver) { ($0, $1) }
.subscribe(onNext: { text, repo in
guard let repo = repo else { return }
repo.desc = text
RepoProvider.update(repo)
}).disposed(by: disposeBag)

updateProfileImage.withLatestFrom(repoObserver) { ($0, $1) }
.subscribe(onNext: { url, repo in
guard let repo = repo else { return }
repo.user?.profileURL = url
RepoProvider.update(repo)
}).disposed(by: disposeBag)

}
}
6 changes: 0 additions & 6 deletions Example/RxCocoa-Texture/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,3 @@ class User: Decodable {
self.profileURL = user.profileURL
}
}

extension User: ASRenderModelProtocol {
var renderModelIdentifier: ASRenderModelIdentifier {
return .init(username, type: type(of: self))
}
}
2 changes: 1 addition & 1 deletion RxCocoa-Texture.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RxCocoa-Texture'
s.version = '2.0.0'
s.version = '2.0.1'
s.summary = 'RxCocoa Extension Library for Texture'

s.description = 'This library is built on Texture with RxCocoa, RxCocoa is a framework that helps make Cocoa APIs used in iOS and OS X easier to use with reactive techniques.'
Expand Down
13 changes: 12 additions & 1 deletion RxCocoa-Texture/Classes/ASBinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import RxCocoa

public struct ASBinder<Value>: ASObserverType {
public typealias E = Value
typealias RenderQueueScheduler = ConcurrentDispatchQueueScheduler
private let _binding: (Event<Value>, ASDisplayNode?) -> ()
private var _directlyBinding: (Value?) -> ()

Expand Down Expand Up @@ -70,9 +69,15 @@ public protocol ASObserverType: ObserverType {

extension ObservableType {
public func bind<O>(to observer: O,
directlyBind: Bool = false,
setNeedsLayout node: ASDisplayNode? = nil)
-> Disposable where O : ASObserverType, Self.E == O.E {
weak var weakNode = node

if directlyBind, let value = (self as? BehaviorRelay<Self.E>)?.value {
observer.directlyBinding(value)
}

return subscribe { event in
switch event {
case .next:
Expand All @@ -90,9 +95,15 @@ extension ObservableType {
}

public func bind<O: ASObserverType>(to observer: O,
directlyBind: Bool = false,
setNeedsLayout node: ASDisplayNode? = nil)
-> Disposable where O.E == E? {
weak var weakNode = node

if directlyBind, let value = (self as? BehaviorRelay<Self.E>)?.value {
observer.directlyBinding(value)
}

return self.map { $0 }.subscribe { observerEvent in
switch observerEvent {
case .next:
Expand Down

0 comments on commit 4d85c26

Please sign in to comment.