@@ -6,6 +6,8 @@ import 'logger.dart';
6
6
import 'reducer.dart' ;
7
7
import 'reducer_exception.dart' ;
8
8
import 'side_effect.dart' ;
9
+ import 'utils.dart' ;
10
+ import 'wrapper_action.dart' ;
9
11
10
12
/// Redux store stream Extension for Stream of actions.
11
13
extension ReduxStoreExt <Action > on Stream <Action > {
@@ -94,7 +96,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
94
96
Stream <S > bind (Stream <A > stream) {
95
97
StreamController <S > controller;
96
98
List <StreamSubscription <dynamic >> subscriptions;
97
- StreamController <_WrapperAction <A >> actionController;
99
+ StreamController <WrapperAction <A >> actionController;
98
100
99
101
void onListen () {
100
102
S state;
@@ -107,13 +109,13 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
107
109
return ;
108
110
}
109
111
110
- void onDataActually (_WrapperAction <A > wrapper) {
112
+ void onDataActually (WrapperAction <A > wrapper) {
111
113
final action = wrapper.action;
112
114
final type = wrapper.type;
113
115
final currentState = state;
114
116
115
117
// add initial state
116
- if (type == _ActionType .initial) {
118
+ if (identical ( type, ActionType .initial) ) {
117
119
final message = '\n '
118
120
' ⟶ Action : $type \n '
119
121
' ⟹ Current state: $currentState ' ;
@@ -149,18 +151,18 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
149
151
}
150
152
}
151
153
152
- actionController = StreamController <_WrapperAction <A >>.broadcast ();
154
+ actionController = StreamController <WrapperAction <A >>.broadcast ();
153
155
154
156
// Call reducer on each action.
155
157
final subscriptionActionController =
156
158
actionController.stream.listen (onDataActually);
157
159
158
160
// Add initial action
159
- actionController.add (_WrapperAction (null , _ActionType .initial));
161
+ actionController.add (WrapperAction (null , ActionType .initial));
160
162
161
163
// Listening to upstream actions
162
164
final subscriptionUpstream = stream
163
- .map ((action) => _WrapperAction (action, _ActionType .external ))
165
+ .map ((action) => WrapperAction (action, ActionType .external ))
164
166
.listen (
165
167
actionController.add,
166
168
onError: controller.addError,
@@ -207,7 +209,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
207
209
}
208
210
209
211
Iterable <StreamSubscription <dynamic >> _listenSideEffects (
210
- StreamController <_WrapperAction <A >> actionController,
212
+ StreamController <WrapperAction <A >> actionController,
211
213
GetState <S > getState,
212
214
StreamController <S > controller,
213
215
) {
@@ -224,8 +226,8 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
224
226
}
225
227
226
228
return actions
227
- .map ((action) =>
228
- _WrapperAction (action, _ActionType .sideEffect (index)))
229
+ .map (
230
+ (action) => WrapperAction (action, ActionType .sideEffect (index)))
229
231
.listen (
230
232
actionController.add,
231
233
onError: controller.addError,
@@ -236,59 +238,3 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
236
238
);
237
239
}
238
240
}
239
-
240
- //
241
- // Internal
242
- //
243
-
244
- @sealed
245
- abstract class _ActionType {
246
- const _ActionType .empty ();
247
-
248
- static const initial = _Initial ();
249
- static const external = _External ();
250
-
251
- const factory _ActionType .sideEffect (int index) = _SideEffect ;
252
-
253
- @override
254
- String toString () {
255
- if (this is _Initial ) {
256
- return '⭍' ;
257
- }
258
- if (this is _External ) {
259
- return '↓' ;
260
- }
261
- if (this is _SideEffect ) {
262
- return '⟳${(this as _SideEffect ).index }' ;
263
- }
264
- throw StateError ('Unknown $this ' );
265
- }
266
- }
267
-
268
- class _Initial extends _ActionType {
269
- const _Initial () : super .empty ();
270
- }
271
-
272
- class _External extends _ActionType {
273
- const _External () : super .empty ();
274
- }
275
-
276
- class _SideEffect extends _ActionType {
277
- final int index;
278
-
279
- const _SideEffect (this .index) : super .empty ();
280
- }
281
-
282
- class _WrapperAction <A > {
283
- final A action;
284
- final _ActionType type;
285
-
286
- _WrapperAction (this .action, this .type);
287
- }
288
-
289
- extension _MapIndexedIterableExtensison <T > on Iterable <T > {
290
- Iterable <R > mapIndexed <R >(R Function (int , T ) mapper) {
291
- var index = 0 ;
292
- return map ((t) => mapper (index++ , t));
293
- }
294
- }
0 commit comments