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

Licensing updates and Improvements to ValueStreamBuilder #778

Merged
merged 6 commits into from
Jan 26, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 0 additions & 201 deletions packages/rxdart/LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions packages/rxdart/LICENSE
1 change: 0 additions & 1 deletion packages/rxdart_flutter/LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions packages/rxdart_flutter/LICENSE
48 changes: 33 additions & 15 deletions packages/rxdart_flutter/lib/src/value_stream_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ typedef ValueStreamBuilderCondition<S> = bool Function(S previous, S current);

/// {@template value_stream_builder}
/// Similar to [StreamBuilder], but works with [ValueStream].
///
/// [ValueStreamBuilder] requires [stream.hasValue] to always be `true`,
/// and the [stream] does not emit any error events.
/// and the [stream] does not emit any error events. See [ValueStreamHasNoValueError]
/// and [UnhandledStreamError] for more information.
///
/// [ValueStreamBuilder] handles building a widget in response to new `data`.
/// [ValueStreamBuilder] is analogous to [StreamBuilder] but has simplified API to
Expand Down Expand Up @@ -161,13 +163,13 @@ class _ValueStreamBuilderState<T> extends State<ValueStreamBuilder<T>> {
final previousData = currentData;
currentData = newData;
if (buildWhen == null || buildWhen(previousData, newData)) {
setState(_emptyFn);
setState(emptyFn);
}
},
onError: (Object e, StackTrace s) {
error = ErrorAndStackTrace(UnhandledStreamError(e), s);
reportError();
setState(_emptyFn);
setState(emptyFn);
},
);
}
Expand All @@ -185,7 +187,7 @@ class _ValueStreamBuilderState<T> extends State<ValueStreamBuilder<T>> {
properties.add(DiagnosticsProperty('subscription', subscription));
}

static void _emptyFn() {}
static void emptyFn() {}

void reportError() {
final error = this.error;
Expand Down Expand Up @@ -215,18 +217,22 @@ class UnhandledStreamError extends Error {

@override
String toString() {
return '''${_bullet}Unhandled error from the ValueStream: "$error".
return '''${_bullet}Unhandled error emitted from the ValueStream: "$error".
${_bullet}The ValueStreamBuilder requires the ValueStream to never emit any error events.
${_bullet}If you are using a BehaviorSubject, ensure you only call subject.add(data),
${_indent}and never call subject.addError(error).
${_bullet}ValueStreamBuilder requires the ValueStream never to emit any error events.
${_indent}You should use one of following methods to handle error before passing stream to ValueStreamBuilder:
$_indent $_bullet stream.handleError((e, s) { })
${_indent}To handle errors before passing the stream to ValueStreamBuilder, you can use one of the following methods:
$_indent $_bullet stream.handleError((error, stackTrace) { })
$_indent $_bullet stream.onErrorReturn(value)
$_indent $_bullet stream.onErrorReturnWith((e) => value)
$_indent $_bullet stream.onErrorReturnWith((error, stackTrace) => value)
$_indent $_bullet stream.onErrorResumeNext(otherStream)
$_indent $_bullet stream.onErrorResume((e) => otherStream)
$_indent $_bullet stream.onErrorResume((error, stackTrace) => otherStream)
$_indent $_bullet stream.transform(
$_indent $_indent StreamTransformer.fromHandlers(handleError: (e, s, sink) {}))
$_indent ...
$_indent $_indent StreamTransformer.fromHandlers(handleError: (error, stackTrace, sink) {}))
$_indent ...
${_bullet}If none of these solutions work, please file a bug at:
${_indent}https://github.com/ReactiveX/rxdart/issues/new
Expand All @@ -243,10 +249,22 @@ class ValueStreamHasNoValueError<T> extends Error {
@override
String toString() {
return '''${_bullet}ValueStreamBuilder requires `hasValue` of "$stream" to be true.
${_indent}You can use BehaviorSubject.seeded(value), publishValueSeeded(value) or shareValueSeeded(value)
${_indent}to create a ValueStream with an initial value.
${_indent}This means the ValueStream must always have the value.
${_indent}If you are using a BehaviorSubject, use `BehaviorSubject.seeded(value)`
or call `subject.add(value)` to provide an initial value before using ValueStreamBuilder.
${_indent}Alternatively, you can create a ValueStream with an initial value using:
$_indent $_bullet stream.publishValueSeeded(value)
$_indent $_bullet stream.shareValueSeeded(value)
$_indent ...
${_bullet}Otherwise, you should check `stream.hasValue` before using ValueStreamBuilder.
${_bullet}Lastly, you can check if the ValueStream has a value before using ValueStreamBuilder, for example:
$_indent if (valueStream.hasValue) {
$_indent return ValueStreamBuilder(...);
$_indent } else {
$_indent return FallBackWidget();
$_indent }
${_bullet}If none of these solutions work, please file a bug at:
${_indent}https://github.com/ReactiveX/rxdart/issues/new
Expand Down
Loading