Skip to content

Commit 9920008

Browse files
authored
2.4.0 (#15)
* deps * fix * 2.4.0 * 2.4.0
1 parent 1580344 commit 9920008

File tree

11 files changed

+122
-94
lines changed

11 files changed

+122
-94
lines changed

.github/workflows/dart.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
container:
15-
image: google/dart:2.12
15+
image: google/dart:latest
1616

1717
steps:
1818
- uses: actions/checkout@v2
@@ -24,7 +24,7 @@ jobs:
2424
run: dart analyze --fatal-infos --fatal-warnings
2525

2626
- name: Format code
27-
run: dartfmt -n ./lib ./test --set-exit-if-changed
27+
run: dart format . --set-exit-if-changed
2828

2929
- name: Active coverage
3030
run: pub global activate coverage
@@ -41,4 +41,4 @@ jobs:
4141
- name: Format coverage
4242
run: pub global run coverage:format_coverage --lcov --in=coverage.json --out=lcov.info --packages=.packages --report-on=lib
4343

44-
- uses: codecov/codecov-action@v1
44+
- uses: codecov/codecov-action@v2.1.0

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Petrus Nguyễn Thái Học <[email protected]>

analysis_options.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
include: package:pedantic/analysis_options.1.11.0.yaml
1+
include: package:lints/recommended.yaml
22

33
analyzer:
44
strong-mode:
55
implicit-casts: false
66
implicit-dynamic: false
7+
78
linter:
89
rules:
910
- prefer_final_locals
1011
- public_member_api_docs
1112
- prefer_relative_imports
13+
# https://github.com/dart-lang/lints#migrating-from-packagepedantic
14+
- always_declare_return_types
15+
- prefer_single_quotes
16+
- unawaited_futures
17+
- unsafe_html

example/selector.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'package:built_collection/built_collection.dart';
22
import 'package:disposebag/disposebag.dart';
3-
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
43
import 'package:pedantic/pedantic.dart';
54
import 'package:rx_redux/rx_redux.dart';
5+
import 'package:rxdart_ext/state_stream.dart';
66

77
//
88
// [BEGIN] STATE
@@ -147,7 +147,7 @@ void main() async {
147147
reducer: reducer);
148148

149149
// select 2 pieces of state and combine them.
150-
final visibleBooks$ = store.select2(
150+
final select2$ = store.select2(
151151
(s) => s.selectedUser?.id,
152152
(s) => s.allBooks,
153153
(String? userId, BuiltList<Book> books) {
@@ -157,7 +157,9 @@ void main() async {
157157
? books.where((b) => b.userId == userId).toBuiltList()
158158
: books;
159159
},
160-
).asBroadcastDistinctValueStream();
160+
);
161+
final visibleBooks$ = select2$
162+
.shareState(select2$.value); // TODO: remove select2$ and shareState
161163

162164
// logging state.
163165
print('~> ${visibleBooks$.value}');

example/todo.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ ViewState reducer(ViewState vs, Action action) {
7373

7474
/// Side effects
7575
76+
// ignore: prefer_function_declarations_over_variables
7677
final SideEffect<Action, ViewState> addTodoEffect = (action$, state) => action$
7778
.where((event) => event.type == ActionType.add)
7879
.map((event) => event.todo)
@@ -87,28 +88,31 @@ Stream<Action> removeTodoEffect(
8788
Stream<Action> action$,
8889
GetState<ViewState> state,
8990
) {
90-
final executeRemove = (Todo todo) async* {
91+
Stream<Action> executeRemove(Todo todo) async* {
9192
await Future<void>.delayed(const Duration(milliseconds: 200));
9293
yield Action(todo, ActionType.removed);
93-
};
94+
}
95+
9496
return action$
9597
.where((event) => event.type == ActionType.remove)
9698
.map((action) => action.todo)
9799
.flatMap(executeRemove);
98100
}
99101

102+
// ignore: prefer_function_declarations_over_variables
100103
final SideEffect<Action, ViewState> toggleTodoEffect = (action$, state) {
101-
final executeToggle = (Todo todo) async* {
104+
Stream<Action> executeToggle(Todo todo) async* {
102105
await Future<void>.delayed(const Duration(milliseconds: 500));
103106
yield Action(todo, ActionType.toggled);
104-
};
107+
}
108+
105109
return action$
106110
.where((event) => event.type == ActionType.toggle)
107111
.map((action) => action.todo)
108112
.flatMap(executeToggle);
109113
};
110114

111-
final delay = () => Future<void>.delayed(const Duration(seconds: 1));
115+
Future<void> delay() => Future<void>.delayed(const Duration(seconds: 1));
112116

113117
void main() async {
114118
final store = RxReduxStore(

lib/src/redux_store_stream_transformer.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
161161
onDone: controller.close,
162162
);
163163

164-
final getState = () => state;
164+
S getState() => state;
165165
final actionStream = actionController.stream
166166
.map((wrapper) => wrapper.action<A>())
167167
.asBroadcastStream(onCancel: (s) => s.cancel());
@@ -195,7 +195,9 @@ class ReduxStoreStreamTransformer<A, S> extends StreamTransformerBase<A, S> {
195195
controller = StreamController<S>(
196196
sync: true,
197197
onListen: onListen,
198+
// ignore: avoid_function_literals_in_foreach_calls
198199
onPause: () => subscriptions?.forEach((s) => s.pause()),
200+
// ignore: avoid_function_literals_in_foreach_calls
199201
onResume: () => subscriptions?.forEach((s) => s.resume()),
200202
onCancel: onCancel,
201203
);

lib/src/selectors.dart

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:async';
22

3-
import 'package:distinct_value_connectable_stream/distinct_value_connectable_stream.dart';
3+
import 'package:rxdart_ext/state_stream.dart';
44

55
import 'store.dart';
66

@@ -30,16 +30,16 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
3030
/// Observe a value of type [Result] exposed from a state stream, and listen only partially to changes.
3131
///
3232
/// The returned Stream is a single-subscription Stream.
33-
DistinctValueStream<Result> select<Result>(
33+
StateStream<Result> select<Result>(
3434
Selector<State, Result> selector, {
3535
Equals<Result>? equals,
3636
}) =>
37-
stateStream.map(selector).distinctValue(selector(state), equals: equals);
37+
stateStream.map(selector).toStateStream(selector(state), equals: equals);
3838

3939
/// Select two sub states and combine them by [projector].
4040
///
4141
/// The returned Stream is a single-subscription Stream.
42-
DistinctValueStream<Result> select2<SubState1, SubState2, Result>(
42+
StateStream<Result> select2<SubState1, SubState2, Result>(
4343
Selector<State, SubState1> selector1,
4444
Selector<State, SubState2> selector2,
4545
Result Function(SubState1 subState1, SubState2 subState2) projector, {
@@ -60,7 +60,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
6060
/// Select three sub states and combine them by [projector].
6161
///
6262
/// The returned Stream is a single-subscription Stream.
63-
DistinctValueStream<Result> select3<SubState1, SubState2, SubState3, Result>(
63+
StateStream<Result> select3<SubState1, SubState2, SubState3, Result>(
6464
Selector<State, SubState1> selector1,
6565
Selector<State, SubState2> selector2,
6666
Selector<State, SubState3> selector3,
@@ -87,7 +87,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
8787
/// Select four sub states and combine them by [projector].
8888
///
8989
/// The returned Stream is a single-subscription Stream.
90-
DistinctValueStream<Result>
90+
StateStream<Result>
9191
select4<SubState1, SubState2, SubState3, SubState4, Result>(
9292
Selector<State, SubState1> selector1,
9393
Selector<State, SubState2> selector2,
@@ -123,7 +123,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
123123
/// Select five sub states and combine them by [projector].
124124
///
125125
/// The returned Stream is a single-subscription Stream.
126-
DistinctValueStream<Result>
126+
StateStream<Result>
127127
select5<SubState1, SubState2, SubState3, SubState4, SubState5, Result>(
128128
Selector<State, SubState1> selector1,
129129
Selector<State, SubState2> selector2,
@@ -173,8 +173,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
173173
/// Select five sub states and combine them by [projector].
174174
///
175175
/// 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>(
178178
Selector<State, SubState1> selector1,
179179
Selector<State, SubState2> selector2,
180180
Selector<State, SubState3> selector3,
@@ -229,8 +229,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
229229
/// Select seven sub states and combine them by [projector].
230230
///
231231
/// 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>(
234234
Selector<State, SubState1> selector1,
235235
Selector<State, SubState2> selector2,
236236
Selector<State, SubState3> selector3,
@@ -291,8 +291,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
291291
/// Select eight sub states and combine them by [projector].
292292
///
293293
/// 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>(
296296
Selector<State, SubState1> selector1,
297297
Selector<State, SubState2> selector2,
298298
Selector<State, SubState3> selector3,
@@ -359,8 +359,8 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
359359
/// Select nine sub states and combine them by [projector].
360360
///
361361
/// 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>(
364364
Selector<State, SubState1> selector1,
365365
Selector<State, SubState2> selector2,
366366
Selector<State, SubState3> selector3,
@@ -433,7 +433,7 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
433433
/// Select many sub states and combine them by [projector].
434434
///
435435
/// The returned Stream is a single-subscription Stream.
436-
DistinctValueStream<Result> selectMany<SubState, Result>(
436+
StateStream<Result> selectMany<SubState, Result>(
437437
List<Selector<State, SubState>> selectors,
438438
List<Equals<SubState>?> subStateEquals,
439439
Result Function(List<SubState> subStates) projector, {
@@ -499,24 +499,24 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
499499
);
500500
}
501501

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);
504504

505505
final eqs = subStateEquals
506-
.map((e) => e ?? DistinctValueStream.defaultEquals)
506+
.map((e) => e ?? StateStream.defaultEquals)
507507
.toList(growable: false);
508508

509509
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) =>
511511
indices.every((i) => eqs[i](previous[i], next[i]));
512512

513513
final currentSubStates = selectSubStates(state);
514514

515515
return stateStream
516516
.map(selectSubStates)
517-
.distinctValue(currentSubStates, equals: subStatesEquals)
517+
.toStateStream(currentSubStates, equals: subStatesEquals)
518518
.map(projector)
519-
.distinctValue(projector(currentSubStates), equals: equals);
519+
.toStateStream(projector(currentSubStates), equals: equals);
520520
}
521521
}
522522

@@ -532,18 +532,17 @@ extension SelectorsExtension<Action, State> on RxReduxStore<Action, State> {
532532
Equals<Object?>? _castToDynamicParams<T>(Equals<T>? f) =>
533533
f == null ? null : (Object? l, Object? r) => f(l as T, r as T);
534534

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,
538537
Selector<State, SubState1> selector1,
539538
Selector<State, SubState2> selector2,
540539
Result Function(SubState1 subState1, SubState2 subState2) projector,
541540
Equals<SubState1>? equals1,
542541
Equals<SubState2>? equals2,
543542
Equals<Result>? equals,
544543
) {
545-
final eq1 = equals1 ?? DistinctValueStream.defaultEquals;
546-
final eq2 = equals2 ?? DistinctValueStream.defaultEquals;
544+
final eq1 = equals1 ?? StateStream.defaultEquals;
545+
final eq2 = equals2 ?? StateStream.defaultEquals;
547546

548547
final controller = StreamController<Result>(sync: true);
549548
StreamSubscription<State>? subscription;
@@ -577,12 +576,12 @@ DistinctValueStream<Result>
577576
return toCancel?.cancel();
578577
};
579578

580-
return controller.stream.distinctValue(initialResult, equals: equals);
579+
return controller.stream.toStateStream(initialResult, equals: equals);
581580
}
582581

583-
DistinctValueStream<Result>
582+
StateStream<Result>
584583
_select3Internal<State, SubState1, SubState2, SubState3, Result>(
585-
DistinctValueStream<State> stateStream,
584+
StateStream<State> stateStream,
586585
Selector<State, SubState1> selector1,
587586
Selector<State, SubState2> selector2,
588587
Selector<State, SubState3> selector3,
@@ -593,9 +592,9 @@ DistinctValueStream<Result>
593592
Equals<SubState3>? equals3,
594593
Equals<Result>? equals,
595594
) {
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;
599598

600599
final controller = StreamController<Result>(sync: true);
601600
StreamSubscription<State>? subscription;
@@ -634,12 +633,12 @@ DistinctValueStream<Result>
634633
return toCancel?.cancel();
635634
};
636635

637-
return controller.stream.distinctValue(initialResult, equals: equals);
636+
return controller.stream.toStateStream(initialResult, equals: equals);
638637
}
639638

640-
DistinctValueStream<Result>
639+
StateStream<Result>
641640
_select4Internal<State, SubState1, SubState2, SubState3, SubState4, Result>(
642-
DistinctValueStream<State> stateStream,
641+
StateStream<State> stateStream,
643642
Selector<State, SubState1> selector1,
644643
Selector<State, SubState2> selector2,
645644
Selector<State, SubState3> selector3,
@@ -657,10 +656,10 @@ DistinctValueStream<Result>
657656
Equals<SubState4>? equals4,
658657
Equals<Result>? equals,
659658
) {
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;
664663

665664
final controller = StreamController<Result>(sync: true);
666665
StreamSubscription<State>? subscription;
@@ -703,5 +702,5 @@ DistinctValueStream<Result>
703702
return toCancel?.cancel();
704703
};
705704

706-
return controller.stream.distinctValue(initialResult, equals: equals);
705+
return controller.stream.toStateStream(initialResult, equals: equals);
707706
}

0 commit comments

Comments
 (0)