@@ -31,7 +31,7 @@ class RxReduxStore<A, S> {
31
31
final void Function (A ) _dispatch;
32
32
33
33
final GetState <S > _getState;
34
- final Stream <S > Function () _stateStream;
34
+ final Stream <S > _stateStream;
35
35
final Stream <A > _actionStream;
36
36
37
37
final Future <void > Function () _dispose;
@@ -62,18 +62,22 @@ class RxReduxStore<A, S> {
62
62
bool Function (S previous, S next) equals,
63
63
RxReduxLogger logger,
64
64
}) {
65
- final actionSubject = StreamController <A >. broadcast (sync : true );
65
+ final actionSubject = StreamController <A >(sync : true );
66
66
final actionOutputController = StreamController <A >.broadcast (sync : true );
67
67
68
- final stateStream = actionSubject.stream.reduxStore <S >(
69
- initialStateSupplier: () => initialState,
70
- sideEffects: [
71
- ...sideEffects,
72
- _onEachActionSideEffect (actionOutputController),
73
- ],
74
- reducer: reducer,
75
- logger: logger,
76
- );
68
+ final stateStream = actionSubject.stream
69
+ .reduxStore <S >(
70
+ initialStateSupplier: () => initialState,
71
+ sideEffects: [
72
+ ...sideEffects,
73
+ _onEachActionSideEffect (actionOutputController),
74
+ ],
75
+ reducer: reducer,
76
+ logger: logger,
77
+ )
78
+ .distinct (equals)
79
+ .skip (1 )
80
+ .asBroadcastStream (onCancel: (subscription) => subscription.cancel ());
77
81
78
82
var currentState = initialState;
79
83
final subscription = stateStream.listen (
@@ -84,11 +88,7 @@ class RxReduxStore<A, S> {
84
88
return RxReduxStore ._(
85
89
actionSubject.add,
86
90
() => currentState,
87
- () => () async * {
88
- yield currentState;
89
- yield * stateStream;
90
- }()
91
- .distinct (equals),
91
+ stateStream,
92
92
actionOutputController.stream,
93
93
() => Future .wait ([
94
94
actionSubject.close (),
@@ -115,7 +115,7 @@ class RxReduxStore<A, S> {
115
115
/// return LoginWidget(state); // build widget based on state.
116
116
/// },
117
117
/// );
118
- Stream <S > get stateStream => _stateStream () ;
118
+ Stream <S > get stateStream => _stateStream;
119
119
120
120
/// Get current state synchronously.
121
121
/// This is useful for filling `initialData` when using `StreamBuilder` in Flutter.
0 commit comments