@@ -7,6 +7,7 @@ import 'logger.dart';
7
7
import 'reducer.dart' ;
8
8
import 'redux_store_stream_transformer.dart' ;
9
9
import 'side_effect.dart' ;
10
+ import 'utils.dart' ;
10
11
11
12
/// Determine equality.
12
13
typedef Equals <T > = bool Function (T previous, T next);
@@ -47,7 +48,7 @@ class RxReduxStore<A, S> {
47
48
final DistinctValueStream <S > _stateStream;
48
49
final Stream <A > _actionStream;
49
50
50
- final DisposeBag _bag;
51
+ final DisposeBag Function () _bag;
51
52
52
53
const RxReduxStore ._(
53
54
this ._dispatch,
@@ -91,14 +92,21 @@ class RxReduxStore<A, S> {
91
92
.handleErrorIfNeeded (errorHandler)
92
93
.publishValueDistinct (initialState, equals: equals);
93
94
94
- final bag = DisposeBag (< Object > [stateStream.connect (), actionController]);
95
+ late final RxReduxStore <A , S > store;
96
+ late final bag = DisposeBag (
97
+ const < Object > [], '( RxReduxStore<$A , $S > ~ ${shortHash (store )} )' );
95
98
96
- return RxReduxStore ._(
99
+ store = RxReduxStore ._(
97
100
actionController.add,
98
101
stateStream,
99
102
actionOutputController.stream,
100
- bag,
103
+ () => bag,
101
104
);
105
+
106
+ stateStream.connect ().disposedBy (bag);
107
+ actionController.disposedBy (bag);
108
+
109
+ return store;
102
110
}
103
111
104
112
/// Get stream of states.
@@ -172,7 +180,7 @@ class RxReduxStore<A, S> {
172
180
/// Stream<LoadNextPageAction> loadNextPageActionStream;
173
181
/// store.dispatchMany(loadNextPageActionStream);
174
182
void dispatchMany (Stream <A > actionStream) =>
175
- _bag.add (actionStream.listen (_dispatch));
183
+ _bag () .add (actionStream.listen (_dispatch));
176
184
177
185
/// Dispose all resources.
178
186
/// This method is typically called in `dispose` method of Flutter `State` object.
@@ -186,7 +194,7 @@ class RxReduxStore<A, S> {
186
194
/// super.dispose();
187
195
/// }
188
196
/// }
189
- Future <void > dispose () => _bag.dispose ();
197
+ Future <void > dispose () => _bag () .dispose ();
190
198
}
191
199
192
200
/// Get current state synchronously.
0 commit comments