Skip to content

Commit

Permalink
Change ReplaySubject's to PublishSubjects
Browse files Browse the repository at this point in the history
Since `self` was being sent to the subjects with a buffer of 1, it was
holding itself in the subjects indefinitely. The weakSelf I added in #30
only affects the closure itself, not the memory semantics of the subject
storing itself.

Looking back at RVMViewModel, they didn't have these as a replay
subject, so I changed them to publish subjects to match their semantics.

The throttling observable can keep it's subject since it's not sending
values of self.

I *think* this is correct, but please correct me on any of this. :)
  • Loading branch information
bobspryn committed Jun 6, 2016
1 parent 780b258 commit 8e68ebf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Pod/Classes/RxViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class RxViewModel: NSObject {
var disposeBag = DisposeBag()

/// The subject for active «signals»
private var activeSubject: ReplaySubject<RxViewModel>?
private var activeSubject: PublishSubject<RxViewModel>?

/// The subject for the inactive «signals»
private var inactiveSubject: ReplaySubject<RxViewModel>?
private var inactiveSubject: PublishSubject<RxViewModel>?

/// Underlying variable that we'll listen to for changes
private dynamic var _active: Bool = false
Expand Down Expand Up @@ -90,7 +90,7 @@ public class RxViewModel: NSObject {
return Observable.deferred { [weak self] () -> Observable<RxViewModel> in
if let weakSelf = self
where weakSelf.activeSubject == nil {
weakSelf.activeSubject = ReplaySubject.create(bufferSize: 1)
weakSelf.activeSubject = PublishSubject()

return weakSelf.activeSubject!
}
Expand All @@ -110,7 +110,7 @@ public class RxViewModel: NSObject {
return Observable.deferred { [weak self] () -> Observable<RxViewModel> in
if let weakSelf = self
where weakSelf.inactiveSubject == nil {
weakSelf.inactiveSubject = ReplaySubject.create(bufferSize: 1)
weakSelf.inactiveSubject = PublishSubject()

return weakSelf.inactiveSubject!
}
Expand Down

0 comments on commit 8e68ebf

Please sign in to comment.