@@ -19,8 +19,6 @@ package com.nhaarman.acorn.presentation
19
19
import androidx.annotation.CallSuper
20
20
import arrow.core.Option
21
21
import arrow.core.toOption
22
- import com.nhaarman.acorn.presentation.RxScene.ContainerEvent.Attached
23
- import com.nhaarman.acorn.presentation.RxScene.ContainerEvent.Detached
24
22
import com.nhaarman.acorn.state.SceneState
25
23
import io.reactivex.Observable
26
24
import io.reactivex.disposables.CompositeDisposable
@@ -75,20 +73,13 @@ abstract class RxScene<V : Container>(
75
73
76
74
private val startedEventsSubject = BehaviorSubject .createDefault(false )
77
75
78
- private val containerEventsSubject = BehaviorSubject .createDefault< ContainerEvent < V >>( Detached )
76
+ private val viewSubject = BehaviorSubject .createDefault( Option .empty< V >() )
79
77
80
78
/* *
81
79
* Publishes a stream of optional [V] instances that are attached to this
82
80
* Scene.
83
81
*/
84
- protected val view: Observable <Option <V >> = containerEventsSubject
85
- .map { event ->
86
- when (event) {
87
- is Attached <V > -> event.v.toOption()
88
- is Detached -> Option .empty()
89
- }
90
- }
91
- .replay(1 ).autoConnect()
82
+ protected val view: Observable <Option <V >> = viewSubject.hide()
92
83
93
84
@CallSuper
94
85
override fun onStart () {
@@ -99,12 +90,12 @@ abstract class RxScene<V : Container>(
99
90
@CallSuper
100
91
override fun attach (v : V ) {
101
92
super .attach(v)
102
- containerEventsSubject .onNext(Attached (v ))
93
+ viewSubject .onNext(v.toOption( ))
103
94
}
104
95
105
96
@CallSuper
106
97
override fun detach (v : V ) {
107
- containerEventsSubject .onNext(Detached )
98
+ viewSubject .onNext(Option .empty() )
108
99
super .detach(v)
109
100
}
110
101
@@ -119,12 +110,6 @@ abstract class RxScene<V : Container>(
119
110
sceneDisposables.dispose()
120
111
}
121
112
122
- @Suppress(" unused" )
123
- private sealed class ContainerEvent <out V > {
124
- class Attached <V >(val v : V ) : ContainerEvent<V>()
125
- object Detached : ContainerEvent<Nothing>()
126
- }
127
-
128
113
/* *
129
114
* A utility function to automatically subscribe and dispose of source
130
115
* [Observable] instance when this Scene starts and stops.
0 commit comments