Skip to content

Commit 809484d

Browse files
committed
Merge pull request #33 from chaserCN/master
fixed observable's disposing
2 parents 78ad23b + c2b8d9e commit 809484d

File tree

5 files changed

+45
-24
lines changed

5 files changed

+45
-24
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
osx_image: xcode7.1
1+
osx_image: xcode7.3
22
language: objective-c
33
podfile: Demo/Podfile
44
cache: cocoapods

Action.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public extension Action {
100100
let work = self.workFactory(input)
101101
defer {
102102
// Subscribe to the work.
103-
work.multicast(buffer).connect()
103+
work.multicast(buffer).connect().addDisposableTo(disposeBag)
104104
}
105105

106-
buffer.subscribe(onNext: { element in
107-
self._elements.onNext(element)
106+
buffer.subscribe(onNext: {[weak self] element in
107+
self?._elements.onNext(element)
108108
},
109-
onError: { error in
110-
self._errors.onNext(ActionError.UnderlyingError(error))
109+
onError: {[weak self] error in
110+
self?._errors.onNext(ActionError.UnderlyingError(error))
111111
},
112112
onCompleted: nil,
113-
onDisposed: {
114-
self.doLocked { self._executing.value = false }
113+
onDisposed: {[weak self] in
114+
self?.doLocked { self?._executing.value = false }
115115
})
116116
.addDisposableTo(disposeBag)
117117

Demo/DemoTests/ActionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class ActionTests: QuickSpec {
214214
it("only subscribes to observable returned from work factory once") {
215215
var invocations = 0
216216
let subject = Action<Void, Void>(workFactory: { _ in
217-
invocations++
217+
invocations += 1
218218
return .empty()
219219
})
220220

Demo/DemoTests/ButtonTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ class ButtonTests: QuickSpec {
106106

107107
expect(disposed) == true
108108
}
109+
110+
it("cancels the observable if the button is deallocated") {
111+
112+
var disposed = false
113+
114+
autoreleasepool {
115+
let subject = UIButton(type: .System)
116+
let action = CocoaAction {
117+
return Observable.create {_ in
118+
AnonymousDisposable {
119+
disposed = true
120+
}
121+
}
122+
}
123+
124+
subject.rx_action = action
125+
subject.rx_action?.execute()
126+
}
127+
128+
expect(disposed) == true
129+
}
109130
}
110131
}
111132

Demo/Podfile.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
PODS:
2-
- Action (1.1.0):
3-
- RxCocoa (~> 2.1.0)
4-
- RxSwift (~> 2.1.0)
5-
- Nimble (3.0.0)
6-
- Quick (0.8.0)
7-
- RxBlocking (2.1.0):
2+
- Action (1.2.1):
3+
- RxCocoa (~> 2.0)
84
- RxSwift (~> 2.0)
9-
- RxCocoa (2.1.0):
10-
- RxSwift (~> 2.0)
11-
- RxSwift (2.1.0)
5+
- Nimble (4.0.1)
6+
- Quick (0.9.2)
7+
- RxBlocking (2.5.0):
8+
- RxSwift (~> 2.5)
9+
- RxCocoa (2.5.0):
10+
- RxSwift (~> 2.5)
11+
- RxSwift (2.5.0)
1212

1313
DEPENDENCIES:
1414
- Action (from `../`)
@@ -23,11 +23,11 @@ EXTERNAL SOURCES:
2323
:path: ../
2424

2525
SPEC CHECKSUMS:
26-
Action: d313d68136ecaa8c8419fcb59d87bd26f2f80522
27-
Nimble: 4c353d43735b38b545cbb4cb91504588eb5de926
28-
Quick: 563d0f6ec5f72e394645adb377708639b7dd38ab
29-
RxBlocking: fa297def258d85c5beae9ed507f94645260b3747
30-
RxCocoa: 79b5feb8378545336e756a0a33fcf5e95050b71c
31-
RxSwift: 110fb07f81c17c2c3b3254d168363057b1880d18
26+
Action: b602680262545973293b0fd0aca84d1a49141608
27+
Nimble: 0f3c8b8b084cda391209c3c5efbb48bedeeb920a
28+
Quick: 18d057bc66451eedd5d1c8dc99ba2a5db6e60226
29+
RxBlocking: 595d9ab56dde6b00beaa5aba40e95b150d2135f1
30+
RxCocoa: e1b1562e57a554d0fb2aabf9d71b637f177257c7
31+
RxSwift: 402b41a50e922a0368fc14cb3bc9f4427920e8ae
3232

3333
COCOAPODS: 0.39.0

0 commit comments

Comments
 (0)