Skip to content

Commit 4b5119a

Browse files
committed
feat: allow a custom equals parameter for ObservableStream
Signed-off-by: Minsu Lee <[email protected]>
1 parent a03acfa commit 4b5119a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

docs/docs/api/observable.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,15 @@ class LoadingIndicator extends StatelessWidget {
268268

269269
## ObservableStream
270270

271-
#### `ObservableStream(Stream<T> stream, {T initialValue, bool cancelOnError, ReactiveContext context})`
271+
#### `ObservableStream(Stream<T> stream, {T initialValue, bool cancelOnError, ReactiveContext context, String? name,
272+
EqualityComparer<dynamic>? equals})`
272273

273274
- **`Stream<T> stream`**: The stream that is tracked for `status` and `value` changes.
274275
- **`T initialValue`**: The starting value of the stream.
275276
- **`bool cancelOnError`**: Should the stream be cancelled on error. Default is set to `false`.
276277
- **`ReactiveContext context`**: the context to which this observable-stream is bound. By default, all `ObservableStream`s are bound to the singleton `mainContext` of the application.
278+
- **`String? name`**: This string is used as a debug name.
279+
- **`EqualityComparer<dynamic>? equals`**: It acts as a comparison function for comparing the previous value with the next value. If this function considers the values to be equal, then the observers will not be re-evaluated.
277280

278281
Similar to `ObservableFuture`, an **`ObservableStream`** provides a reactive wrapper around a `Stream`. This gives an easy way to observe and re-render whenever there is new `data`, or `error` or a `status` change on the `ObservableStream`.
279282

mobx/lib/src/api/async/observable_stream.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ObservableStream<T> implements Stream<T>, ObservableValue<T?> {
3636
///
3737
/// If `cancelOnError` is `true`, the stream will be cancelled when an error
3838
/// event is emitted by the source stream. The default value is `false`.
39+
///
40+
/// It is possible to override equality comparison of new values with [equals].
3941
ObservableStream(Stream<T> stream,
4042
{T? initialValue,
4143
bool cancelOnError = false,

0 commit comments

Comments
 (0)