Skip to content

[Question]: Any thoughts on difference between ignoreChange and distinct? #241

@Fnll

Description

@Fnll

Hi, new dart beginner here. As far as I can see, the widget update process will spawn a stream which could be cancelled both when ignoreChange implemented, and distinct is set true. I'm not seeing any difference using one of the two, and confused about it. Not sure if there is any consideration I've missed?

  void _createStream() {
    _stream = widget.store.onChange
        .where(_ignoreChange)
        .map((_) => widget.converter(widget.store))
        .transform(StreamTransformer.fromHandlers(
          handleError: _handleConverterError,
        ))
        // Don't use `Stream.distinct` because it cannot capture the initial
        // ViewModel produced by the `converter`.
        .where(_whereDistinct)
        // After each ViewModel is emitted from the Stream, we update the
        // latestValue. Important: This must be done after all other optional
        // transformations, such as ignoreChange.
        .transform(StreamTransformer.fromHandlers(
          handleData: _handleChange,
        ))
        // Handle any errors from converter/onWillChange/onDidChange
        .transform(StreamTransformer.fromHandlers(
          handleError: _handleError,
        ));
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions