1
1
import 'dart:async' ;
2
2
3
- import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream .dart' ;
3
+ import 'package:rxdart_ext/state_stream .dart' ;
4
4
5
5
import 'store.dart' ;
6
6
@@ -30,16 +30,16 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
30
30
/// Observe a value of type [Result] exposed from a state stream, and listen only partially to changes.
31
31
///
32
32
/// The returned Stream is a single-subscription Stream.
33
- DistinctValueStream <Result > select <Result >(
33
+ StateStream <Result > select <Result >(
34
34
Selector <State , Result > selector, {
35
35
Equals <Result >? equals,
36
36
}) =>
37
- stateStream.map (selector).distinctValue (selector (state), equals: equals);
37
+ stateStream.map (selector).toStateStream (selector (state), equals: equals);
38
38
39
39
/// Select two sub states and combine them by [projector] .
40
40
///
41
41
/// The returned Stream is a single-subscription Stream.
42
- DistinctValueStream <Result > select2 <SubState1 , SubState2 , Result >(
42
+ StateStream <Result > select2 <SubState1 , SubState2 , Result >(
43
43
Selector <State , SubState1 > selector1,
44
44
Selector <State , SubState2 > selector2,
45
45
Result Function (SubState1 subState1, SubState2 subState2) projector, {
@@ -60,7 +60,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
60
60
/// Select three sub states and combine them by [projector] .
61
61
///
62
62
/// The returned Stream is a single-subscription Stream.
63
- DistinctValueStream <Result > select3 <SubState1 , SubState2 , SubState3 , Result >(
63
+ StateStream <Result > select3 <SubState1 , SubState2 , SubState3 , Result >(
64
64
Selector <State , SubState1 > selector1,
65
65
Selector <State , SubState2 > selector2,
66
66
Selector <State , SubState3 > selector3,
@@ -87,7 +87,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
87
87
/// Select four sub states and combine them by [projector] .
88
88
///
89
89
/// The returned Stream is a single-subscription Stream.
90
- DistinctValueStream <Result >
90
+ StateStream <Result >
91
91
select4 <SubState1 , SubState2 , SubState3 , SubState4 , Result >(
92
92
Selector <State , SubState1 > selector1,
93
93
Selector <State , SubState2 > selector2,
@@ -123,7 +123,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
123
123
/// Select five sub states and combine them by [projector] .
124
124
///
125
125
/// The returned Stream is a single-subscription Stream.
126
- DistinctValueStream <Result >
126
+ StateStream <Result >
127
127
select5 <SubState1 , SubState2 , SubState3 , SubState4 , SubState5 , Result >(
128
128
Selector <State , SubState1 > selector1,
129
129
Selector <State , SubState2 > selector2,
@@ -173,8 +173,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
173
173
/// Select five sub states and combine them by [projector] .
174
174
///
175
175
/// The returned Stream is a single-subscription Stream.
176
- DistinctValueStream <Result > select6< SubState1 , SubState2 , SubState3 ,
177
- SubState4 , SubState5 , SubState6 , Result > (
176
+ StateStream <Result > select6< SubState1 , SubState2 , SubState3 , SubState4 ,
177
+ SubState5 , SubState6 , Result > (
178
178
Selector <State , SubState1 > selector1,
179
179
Selector <State , SubState2 > selector2,
180
180
Selector <State , SubState3 > selector3,
@@ -229,8 +229,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
229
229
/// Select seven sub states and combine them by [projector] .
230
230
///
231
231
/// The returned Stream is a single-subscription Stream.
232
- DistinctValueStream <Result > select7< SubState1 , SubState2 , SubState3 ,
233
- SubState4 , SubState5 , SubState6 , SubState7 , Result > (
232
+ StateStream <Result > select7< SubState1 , SubState2 , SubState3 , SubState4 ,
233
+ SubState5 , SubState6 , SubState7 , Result > (
234
234
Selector <State , SubState1 > selector1,
235
235
Selector <State , SubState2 > selector2,
236
236
Selector <State , SubState3 > selector3,
@@ -291,8 +291,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
291
291
/// Select eight sub states and combine them by [projector] .
292
292
///
293
293
/// The returned Stream is a single-subscription Stream.
294
- DistinctValueStream <Result > select8< SubState1 , SubState2 , SubState3 ,
295
- SubState4 , SubState5 , SubState6 , SubState7 , SubState8 , Result > (
294
+ StateStream <Result > select8< SubState1 , SubState2 , SubState3 , SubState4 ,
295
+ SubState5 , SubState6 , SubState7 , SubState8 , Result > (
296
296
Selector <State , SubState1 > selector1,
297
297
Selector <State , SubState2 > selector2,
298
298
Selector <State , SubState3 > selector3,
@@ -359,8 +359,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
359
359
/// Select nine sub states and combine them by [projector] .
360
360
///
361
361
/// The returned Stream is a single-subscription Stream.
362
- DistinctValueStream <Result > select9< SubState1 , SubState2 , SubState3 ,
363
- SubState4 , SubState5 , SubState6 , SubState7 , SubState8 , SubState9 , Result > (
362
+ StateStream <Result > select9< SubState1 , SubState2 , SubState3 , SubState4 ,
363
+ SubState5 , SubState6 , SubState7 , SubState8 , SubState9 , Result > (
364
364
Selector <State , SubState1 > selector1,
365
365
Selector <State , SubState2 > selector2,
366
366
Selector <State , SubState3 > selector3,
@@ -433,7 +433,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
433
433
/// Select many sub states and combine them by [projector] .
434
434
///
435
435
/// The returned Stream is a single-subscription Stream.
436
- DistinctValueStream <Result > selectMany <SubState , Result >(
436
+ StateStream <Result > selectMany <SubState , Result >(
437
437
List <Selector <State , SubState >> selectors,
438
438
List <Equals <SubState >?> subStateEquals,
439
439
Result Function (List <SubState > subStates) projector, {
@@ -499,24 +499,24 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
499
499
);
500
500
}
501
501
502
- final selectSubStates =
503
- ( State state) => selectors.map ((s) => s (state)).toList (growable: false );
502
+ List < SubState > selectSubStates ( State state) =>
503
+ selectors.map ((s) => s (state)).toList (growable: false );
504
504
505
505
final eqs = subStateEquals
506
- .map ((e) => e ?? DistinctValueStream .defaultEquals)
506
+ .map ((e) => e ?? StateStream .defaultEquals)
507
507
.toList (growable: false );
508
508
509
509
late final indices = Iterable <int >.generate (length);
510
- final subStatesEquals = (List <SubState > previous, List <SubState > next) =>
510
+ bool subStatesEquals (List <SubState > previous, List <SubState > next) =>
511
511
indices.every ((i) => eqs[i](previous[i], next[i]));
512
512
513
513
final currentSubStates = selectSubStates (state);
514
514
515
515
return stateStream
516
516
.map (selectSubStates)
517
- .distinctValue (currentSubStates, equals: subStatesEquals)
517
+ .toStateStream (currentSubStates, equals: subStatesEquals)
518
518
.map (projector)
519
- .distinctValue (projector (currentSubStates), equals: equals);
519
+ .toStateStream (projector (currentSubStates), equals: equals);
520
520
}
521
521
}
522
522
@@ -532,18 +532,17 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
532
532
Equals <Object ?>? _castToDynamicParams <T >(Equals <T >? f) =>
533
533
f == null ? null : (Object ? l, Object ? r) => f (l as T , r as T );
534
534
535
- DistinctValueStream <Result >
536
- _select2Internal <State , SubState1 , SubState2 , Result >(
537
- DistinctValueStream <State > stateStream,
535
+ StateStream <Result > _select2Internal <State , SubState1 , SubState2 , Result >(
536
+ StateStream <State > stateStream,
538
537
Selector <State , SubState1 > selector1,
539
538
Selector <State , SubState2 > selector2,
540
539
Result Function (SubState1 subState1, SubState2 subState2) projector,
541
540
Equals <SubState1 >? equals1,
542
541
Equals <SubState2 >? equals2,
543
542
Equals <Result >? equals,
544
543
) {
545
- final eq1 = equals1 ?? DistinctValueStream .defaultEquals;
546
- final eq2 = equals2 ?? DistinctValueStream .defaultEquals;
544
+ final eq1 = equals1 ?? StateStream .defaultEquals;
545
+ final eq2 = equals2 ?? StateStream .defaultEquals;
547
546
548
547
final controller = StreamController <Result >(sync : true );
549
548
StreamSubscription <State >? subscription;
@@ -577,12 +576,12 @@ DistinctValueStream<Result>
577
576
return toCancel? .cancel ();
578
577
};
579
578
580
- return controller.stream.distinctValue (initialResult, equals: equals);
579
+ return controller.stream.toStateStream (initialResult, equals: equals);
581
580
}
582
581
583
- DistinctValueStream <Result >
582
+ StateStream <Result >
584
583
_select3Internal <State , SubState1 , SubState2 , SubState3 , Result >(
585
- DistinctValueStream <State > stateStream,
584
+ StateStream <State > stateStream,
586
585
Selector <State , SubState1 > selector1,
587
586
Selector <State , SubState2 > selector2,
588
587
Selector <State , SubState3 > selector3,
@@ -593,9 +592,9 @@ DistinctValueStream<Result>
593
592
Equals <SubState3 >? equals3,
594
593
Equals <Result >? equals,
595
594
) {
596
- final eq1 = equals1 ?? DistinctValueStream .defaultEquals;
597
- final eq2 = equals2 ?? DistinctValueStream .defaultEquals;
598
- final eq3 = equals3 ?? DistinctValueStream .defaultEquals;
595
+ final eq1 = equals1 ?? StateStream .defaultEquals;
596
+ final eq2 = equals2 ?? StateStream .defaultEquals;
597
+ final eq3 = equals3 ?? StateStream .defaultEquals;
599
598
600
599
final controller = StreamController <Result >(sync : true );
601
600
StreamSubscription <State >? subscription;
@@ -634,12 +633,12 @@ DistinctValueStream<Result>
634
633
return toCancel? .cancel ();
635
634
};
636
635
637
- return controller.stream.distinctValue (initialResult, equals: equals);
636
+ return controller.stream.toStateStream (initialResult, equals: equals);
638
637
}
639
638
640
- DistinctValueStream <Result >
639
+ StateStream <Result >
641
640
_select4Internal <State , SubState1 , SubState2 , SubState3 , SubState4 , Result >(
642
- DistinctValueStream <State > stateStream,
641
+ StateStream <State > stateStream,
643
642
Selector <State , SubState1 > selector1,
644
643
Selector <State , SubState2 > selector2,
645
644
Selector <State , SubState3 > selector3,
@@ -657,10 +656,10 @@ DistinctValueStream<Result>
657
656
Equals <SubState4 >? equals4,
658
657
Equals <Result >? equals,
659
658
) {
660
- final eq1 = equals1 ?? DistinctValueStream .defaultEquals;
661
- final eq2 = equals2 ?? DistinctValueStream .defaultEquals;
662
- final eq3 = equals3 ?? DistinctValueStream .defaultEquals;
663
- final eq4 = equals4 ?? DistinctValueStream .defaultEquals;
659
+ final eq1 = equals1 ?? StateStream .defaultEquals;
660
+ final eq2 = equals2 ?? StateStream .defaultEquals;
661
+ final eq3 = equals3 ?? StateStream .defaultEquals;
662
+ final eq4 = equals4 ?? StateStream .defaultEquals;
664
663
665
664
final controller = StreamController <Result >(sync : true );
666
665
StreamSubscription <State >? subscription;
@@ -703,5 +702,5 @@ DistinctValueStream<Result>
703
702
return toCancel? .cancel ();
704
703
};
705
704
706
- return controller.stream.distinctValue (initialResult, equals: equals);
705
+ return controller.stream.toStateStream (initialResult, equals: equals);
707
706
}
0 commit comments