brianegan / flutter_redux

A library that connects Widgets to a Redux Store
MIT License
1.65k stars 219 forks source link

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

Open Fnll opened 2 years ago

Fnll commented 2 years ago

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,
        ));
  }