Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/rename states children #91

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/src/observables/states/states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@ class States<T> {
): this.from(Observable(observe));

static States<R> combine<T, R>({
required List<States<T>> children,
required List<States<T>> states,
required R Function(List<T> items) combiner,
}) => Observable.combine<T, R>(
observables: children
observables: states
.map((states) => states.observable)
.toList(),
combiner: combiner,
).asStates();

static States<R> combine2<T1, T2, R>({
required States<T1> child1,
required States<T2> child2,
required States<T1> states1,
required States<T2> states2,
required R Function(T1, T2) combiner,
}) => Observable.combine2<T1, T2, R>(
observable1: child1.observable,
observable2: child2.observable,
observable1: states1.observable,
observable2: states2.observable,
combiner: combiner,
).asStates();

static States<R> combine3<T1, T2, T3, R>({
required States<T1> child1,
required States<T2> child2,
required States<T3> child3,
required States<T1> states1,
required States<T2> states2,
required States<T3> states3,
required R Function(T1, T2, T3) combiner,
}) => Observable.combine3<T1, T2, T3, R>(
observable1: child1.observable,
observable2: child2.observable,
observable3: child3.observable,
observable1: states1.observable,
observable2: states2.observable,
observable3: states3.observable,
combiner: combiner,
).asStates();

Expand Down Expand Up @@ -109,7 +109,7 @@ extension StatesX<T> on States<T> {

StatesActivated<T> activated() {
return StatesActivated<T>(
child: this
states: this
);
}
}
10 changes: 5 additions & 5 deletions lib/src/observables/states/states_activated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ abstract class HasStates<T> {
abstract class StatesActivated<T> implements HasStates<T>, Disposable {
@internal
factory StatesActivated({
required States<T> child
required States<T> states
}) = _StatesActivated;
}

class _StatesActivated<T> implements StatesActivated<T> {

_StatesActivated({
required States<T> child
}): _child = child {
required States<T> states
}): _states = states {
_startObserve();
}

final States<T> _child;
final States<T> _states;
final _subject = ReplaySubject<T>(bufferSize: 1);

@override
Expand All @@ -34,7 +34,7 @@ class _StatesActivated<T> implements StatesActivated<T> {
late final Disposable _observation;

void _startObserve() {
_observation = _child.observe(_subject.onData);
_observation = _states.observe(_subject.onData);
}

void _stopObserve() {
Expand Down
48 changes: 24 additions & 24 deletions test/observables/states/states_combine_test.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/test_gen/combine_test/shared/codes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ String statesCombine(int? number) {
String _combine(bool isObservable, int? number) {
final type = isObservable ? 'Observable' : 'States';
final name = isObservable ? 'observable' : 'states';
final sources = isObservable ? 'observables' : 'children';
final source = isObservable ? 'observable' : 'child';
final sources = isObservable ? 'observables' : 'states';
final source = isObservable ? 'observable' : 'states';
if (number == null) {
return '''
final combine = $type.combine<String, String>(
Expand Down