Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Frank Pepermans
    @frankpepermans
    We ideally want to fix this, map is native and returns a MapStream, which isn't a ValueStream. In beta 2 all rx ops do keep the type of the original stream
    Matias Meno
    @enyo
    @frankpepermans oooh, that sounds great. Does that mean, that a map will work even without a listener?
    Or is this problem going to persist
    Frank Pepermans
    @frankpepermans
    Without a listener? No, basically everything triggers upon onListen internally
    Matias Meno
    @enyo
    Hi. I've just started implementing the bloc library in my app, and used their example for a form. I've realised this issue: felangel/bloc#1888
    Could somebody help me find a solution to do this properly?
    So basically, there are events that represent an input field change (EmailChanged and PasswordChanged events)
    To avoid rebuilding the form and doing unnecessary validations, these are debounced:
    final debounced = events
            .where((event) => event is! FormSubmitted)
            .debounceTime(const Duration(milliseconds: 300));
    They are then merged with the FormSubmitted event like this:
    return events
            .where((event) => event is FormSubmitted)
            .mergeWith([debounced])
    The problem with that is, that EmailChangedand PasswordChanged events could be triggered, being debounced, and then the FormSubmitted event could arrive, and be handled before the change events are being handled
    Matias Meno
    @enyo
    Is there an elegant way to handle this issue with rxdart?
    Frank Pepermans
    @frankpepermans
    For sure,
    You could go with combineLatest or switchMap for starters, can the submit only happen when both fields are valid?
    Petrus Nguyễn Thái Học
    @hoc081098
    @enyo Trying use throttleTime(leading: true, trailing: true) 😂
    Matias Meno
    @enyo
    @frankpepermans The submit can only happen when both fields are valid yes. But the case the worries me more is when both are already valid, and changes are made and then submitted before they arrive
    Frank Pepermans
    @frankpepermans
    This is very rough, and can be improved, but the idea is that any change to either field would reset the sequence to valid = false and would block submit.
    final onEmail = PublishSubject<String>(),
            onPassword = PublishSubject<String>();
        final onSubmit = PublishSubject<bool>();
        final email = onEmail.debounceTime(const Duration(seconds: 1)),
            password = onPassword.debounceTime(const Duration(seconds: 1));
    
        bool Function(String) validateEmail, validatePassword;
    
        final onSyncInput = Rx.merge([onEmail, onPassword]);
        final onValid = Rx.combineLatest2(email.map(validateEmail),
            password.map(validatePassword), (e, p) => e && p);
    
        onSyncInput
            .switchMap((_) => onValid)
            .switchMap((canSubmit) => canSubmit ? onSubmit : Stream.value(false));
    Matias Meno
    @enyo
    Thanks!
    turtleclawstudios
    @turtleclawstudios
    Hi, i have a stream of AuthUser and using the ID from that stream, i'd like to create another stream for the UserProfile
    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.