@@ -26,7 +26,11 @@ import rx.joins.ObserverBase
26
26
*/
27
27
trait Observer [- T ] {
28
28
29
- def asJavaObserver : rx.Observer [_ >: T ]
29
+ private [scala] def asJavaObserver : rx.Observer [_ >: T ] = new ObserverBase [T ] {
30
+ protected def onCompletedCore (): Unit = onCompleted()
31
+ protected def onErrorCore (error : Throwable ): Unit = onError(error)
32
+ protected def onNextCore (value : T ): Unit = onNext(value)
33
+ }
30
34
31
35
/**
32
36
* Provides the Observer with new data.
@@ -35,78 +39,35 @@ trait Observer[-T] {
35
39
*
36
40
* The [[rx.lang.scala.Observable ]] will not call this method again after it calls either `onCompleted` or `onError`.
37
41
*/
38
- def onNext (value : T ): Unit = asJavaObserver.onNext(value)
42
+ def onNext (value : T ): Unit
39
43
40
44
/**
41
45
* Notifies the Observer that the [[rx.lang.scala.Observable ]] has experienced an error condition.
42
46
*
43
47
* If the [[rx.lang.scala.Observable ]] calls this method, it will not thereafter call `onNext` or `onCompleted`.
44
48
*/
45
- def onError (error : Throwable ): Unit = asJavaObserver.onError(error)
49
+ def onError (error : Throwable ): Unit
46
50
47
51
/**
48
52
* Notifies the Observer that the [[rx.lang.scala.Observable ]] has finished sending push-based notifications.
49
53
*
50
54
* The [[rx.lang.scala.Observable ]] will not call this method if it calls `onError`.
51
55
*/
52
- def onCompleted (): Unit = asJavaObserver.onCompleted()
56
+ def onCompleted (): Unit
53
57
54
58
}
55
59
56
60
object Observer {
57
-
58
- private [scala] def apply [T ](observer : rx.Observer [T ]) : Observer [T ] = {
59
- new Observer [T ]() {
60
- def asJavaObserver : rx.Observer [_ >: T ] = observer
61
- }
62
- }
63
-
64
61
/**
65
- * Creates an [[rx.lang.scala.Observer ]]
66
- * @param onNext the onNext action
67
- * @param onError the onError action
68
- * @param onCompleted the onCompleted action
62
+ * Assume that the underlying rx.Observer does not need to be wrapped
69
63
*/
70
- def apply [T ](onNext : T => Unit , onError : Throwable => Unit , onCompleted : () => Unit ): Observer [T ] = {
71
- Observer (new ObserverBase [T ] () {
72
- protected def onCompletedCore (): Unit = onCompleted()
73
- protected def onErrorCore (error : Throwable ): Unit = onError(error)
74
- protected def onNextCore (value : T ): Unit = onNext(value)
75
- })
76
- }
77
-
78
- /**
79
- * Creates an [[rx.lang.scala.Observer ]]
80
- * @param onNext the onNext action
81
- * @param onError the onError action
82
- */
83
- def apply [T ](onNext : T => Unit , onError : Throwable => Unit ): Observer [T ] = {
84
- Observer (new ObserverBase [T ] () {
85
- protected def onCompletedCore (): Unit = {}
86
- protected def onErrorCore (error : Throwable ): Unit = onError(error)
87
- protected def onNextCore (value : T ): Unit = onNext(value)
88
- })
89
- }
90
-
91
- def apply [T ](onNext : T => Unit , onCompleted : () => Unit ): Observer [T ] = {
92
- Observer (new ObserverBase [T ] () {
93
- protected def onCompletedCore (): Unit = onCompleted()
94
- protected def onErrorCore (error : Throwable ): Unit = {}
95
- protected def onNextCore (value : T ): Unit = onNext(value)
96
- })
97
- }
98
-
99
- /**
100
- * Creates an [[rx.lang.scala.Observer ]]
101
- * @param onNext the onNext action
102
- */
103
- def apply [T ](onNext : T => Unit ): Observer [T ] = {
104
- Observer (new ObserverBase [T ] () {
105
- protected def onCompletedCore (): Unit = {}
106
- protected def onErrorCore (error : Throwable ): Unit = {}
107
- protected def onNextCore (value : T ): Unit = onNext(value)
108
- })
109
- }
110
- }
111
-
64
+ private [scala] def apply [T ](observer : rx.Observer [T ]) : Observer [T ] = {
65
+ new Observer [T ]() {
66
+ override def asJavaObserver : rx.Observer [_ >: T ] = observer
112
67
68
+ def onCompleted (): Unit = asJavaObserver.onCompleted()
69
+ def onError (error : Throwable ): Unit = asJavaObserver.onError(error)
70
+ def onNext (value : T ): Unit = asJavaObserver.onNext(value)
71
+ }
72
+ }
73
+ }
0 commit comments