Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    turtleclawstudios
    @turtleclawstudios
    But if the AuthUser stream emits another item, which means another user has signed in, i need to automatically make sure the UserProfile stream switches as well
    how can i achieve such functionality>
    I think I need a way of transforming a stream into another stream, and if the original stream emits another item, the downstream stream needs to see it and change.
    Frank Pepermans
    @frankpepermans
    Sounds like you want either switchMap, flatMap or asyncExpand.
    So your choice depends, do you only care for the very latest event in the original stream? Then use switchMap. Do you want to handle every event? Use the others, with flatMap, the downstream emits whenever a transformation is completed, with asyncExpand, it will await each transformation and emit.
    Arnal Shoorukov
    @ArnalShoorukov
    Hello
    where i can improve my skills in rxdart
    any suggestion
    Frank Pepermans
    @frankpepermans
    Hey @ArnalShoorukov,
    I'd suggest just creating a toy project with rxdart, we have less docs than rxjs for example, but then again, you can always use those docs to help you forward with rxdart, since the api is very similar.
    willladislaw
    @willladislaw
    The statusTransformer() obtains the value (boolean) via an api call for a given username. In some cases, value is already available for a given username and the statusTransformer() not required, When this is the case, I need to somehow update the value inside Map for the username. I may need an appropriate transformer for this but not sure of the type of transformer required.
     final _streamCtrl = BehaviorSubject<String>();
    
    Stream<Map<String, Future<bool>>> status$;
        status$ = __streamCtrl.stream
            .transform(transformers.statusTransformer());
    
    statusTransformer() {
        return ScanStreamTransformer(
          (Map<String, Future<bool>> cache, String username, index) {
            cache[username] = _provider.fetchIDataFromApi(username);
            return cache;
          },
          <String, Future<bool>>{},
        );
    }
    Petrus Nguyễn Thái Học
    @hoc081098
    Just check cache.containsKey(username).
    statusTransformer() {
      return ScanStreamTransformer(
            (Map<String, Future<bool>> cache, String username, index) {
              if (cache.containsKey(username)) {
                return cache;
              }
    
          cache[username] = _provider.fetchIDataFromApi(username);
          return cache;
        },
        <String, Future<bool>>{},
      );
    }
    willladislaw
    @willladislaw
    @hoc081098 How would you update the cached value?
    Frank Pepermans
    @frankpepermans
    Did you check out Bloc/Cubit? There you could handle the Map as an inner state and expose it like a Stream.
    willladislaw
    @willladislaw
    Example?
    Frank Pepermans
    @frankpepermans
    willladislaw
    @willladislaw
    Seems to be an overkill for this one task. No other way through rxdart?
    Hadrien Lejard
    @hashes:matrix.org
    [m]
    @willladislaw if you use BehaviorSubject you can use the .add(value) method
    willladislaw
    @willladislaw
    BehaviorSubject takes a String key (username), which is passed on to the above transformer. I guess there is no other way. Nevermind!
    Frank Pepermans
    @frankpepermans
    Well you could always combine multiple streams into one, maybe just write down exactly what you wish to achieve?
    Denis Beketsky
    @TatsuUkraine
    Hi everyone. Probably this question already was asked multiple times, but I can't seems to find the final answer on it. When at least one source stream in CombineLatestStream emits an error, should result stream still produce value events?
    I looked at the source code and it looks to me that it's an issue. And I would like to provide a solution for this. But I'm not sure if I should create a PR with fix in the existing combine latest stream implementation, or if it's expected behavior - propose a new stream?
    Frank Pepermans
    @frankpepermans
    Not 100%, been a while and on mobile so cannot check, but it should follow the Dart streams in that way:
    StreamControllers and also Subjects can have cancelOnError is true, so combine latest would stop if both had an error, but will keep going with the other one if just one errored then. Maybe we could add a cancelOnError as well in the combineLatest handler.
    Denis Beketsky
    @TatsuUkraine
    I see. I don't know what the best way will be to handle this) in a first place I'm curious if it's a bug or future)
    In my understanding - a bug, since if one of the source streams has an error, latest even there - an error, so combine latest shouldn't produce a value events if the second source stream emitted a value event after that
    Denis Beketsky
    @TatsuUkraine
    @frankpepermans what is the behavior for thos scenario in other implementations?
    Frank Pepermans
    @frankpepermans
    Check Dart streams and cancelOnError, rxDart is built upon Dart streams. As combineLatest kind of is a new Stream controller, it makes sense to allow this property here as well.
    Denis Beketsky
    @TatsuUkraine
    But it's not quite cancel on error, since combine stream should still be live when error occures.
    If take Dart streams cancelOrError during subscription means that subscription will be cancelled, while in the described scenario I feel like combine stream still should emit value, which means it still should listen for all source streams.
    So for instance we have streamA and stream B, assume streamA and streamB emitted values. Then streamA fires an error. Then streamB fires an event.
    Denis Beketsky
    @TatsuUkraine
    What heppens now - when streamB fired the event, combine latest will emit an event with latest event from streamA and streamB. Which is not quite expected behavior as for me, since latests event in streamA was an error not a data.
    Moving forward, let's assume that now streamA emits the data event, combine latest in this scenario should remain its normal workflow by producing event with most recent data from streamA and streamB.
    Frank Pepermans
    @frankpepermans
    Ah I see sorry I misunderstood,
    Hmmm to solve it today, maybe try to use materialize on the separate streams? Then, you should get a wrapped object, where the data can be either a value or an error. This way you keep track of the actual states in both streams via the combiner?
    Denis Beketsky
    @TatsuUkraine
    well yeah, I mean I can figure out some workarounds I think. At this point I'm curious what is the expected behavior for CombineLatestStream. If it's not expected I can provide a fix, it should be a relatively simple one. But if it's expected - I can provide a new type of stream that will be aware of error events
    I created an issue on github with the simple test case for such scenario ReactiveX/rxdart#641
    just trying to understand if it's really an issue
    Denis Beketsky
    @TatsuUkraine
    btw, cool solution with materializer
    Frank Pepermans
    @frankpepermans
    It was indeed intentionally designed to see the latest values regardless of errors, since the errors pass down via onError handlers. So then maybe 2 new optional parameters are needed, still the cancelOnError one, since it cannot be resolved always from the source streams, plus the a new one to prevent emission when one is in an error state, e.g. ignoreErrorStates which is then true by default for backwards compatibility.
    Denis Beketsky
    @TatsuUkraine
    👍ok, thank you for your help, I will add your answer in a ticket a little bit later as a proposition)
    Fabian Freund
    @FaFre
    H
    Fabian Freund
    @FaFre
    Hey guys, i have a stream that emits a list of URLs. Now I want to have another stream that listens for the URL lists to fetch and process data from a webservice. However, when a new list of URLs is emitted the current fetch/process should be canceled and the new list should be processed. Only successfully processed jobs will be emitted by the second stream.
    Can somebody give me a hint how to realize that with rxdart?
    Frank Pepermans
    @frankpepermans
    Sounds like switchMap from your description, you basically switch to the other Stream, but when the first one emits again, it cancels and does the switch again with the newest value.
    Lukáš Chábek
    @Lukasas
    Hello, I'd like to ask, I got a stream that pulls data and then a stream that caches them. I need something to start the first stream and when it finishes get the data and start the cache stream. What would be the best approach ? (rxdart)
    Frank Pepermans
    @frankpepermans
    What do you mean exactly?
    Do you need to cache every item from Stream A?
    Fabian Freund
    @FaFre

    Sounds like switchMap from your description, you basically switch to the other Stream, but when the first one emits again, it cancels and does the switch again with the newest value.

    thanks for your suggestion that time, it hit the nail :)

    in the meanwhile I was using rxdart for a lot of things, its really a great library!

    I also like the BehaviorSubject and make more and more use of it. Sometimes I want to 'upgrade' existing streams (I don't have control over) just to gain easy access to the last value.

    I do this like this:

    final gridSubject = BehaviorSubject<List<Grid>>();
    gridStream.pipe(gridSubject);

    I was wondering if this approach is suggested?