Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Deva Palanisamy
    @frankpepermans thanks for creating powerful library
    Matias Meno
    Hi! Just made the 22_to_23 switch
    so far everything seemed to work fine, but there's one error that I get now:
    .shareValue() doesn't exist anymore
    Since it's an extension I need to import rxdart for it to exist.
    Got it :)
    Great job! Thanks for also providing the codemod
    One suggestion though: add the .seeded() factory constructor to the codemod
    I had to replace all of this manually
    Frank Pepermans
    great :) we're on 0.24.1 meanwhile, but that shouldn't be too big a change
    Rafael Corbellini
    Hello, I would like to know how do I execute a function when something is emitted (sink / add) in the controller, I know doOnData but it only works if someone is listening to the stream.
    Jack Reilly
    I have a common usage where I want a ValueStream which doesn't shut down when it no longer has listeners. You could imagine that you have a global ValueStream for a Firestore document, and you never want this stream to close due to changes in the number of subscribers, e.g. The workaround I have right now is to register a no-op listener upon creation of the ValueStream, which then "tricks" the stream into thinking it always has a listener. Is there a better pattern I could adopt for this?
    Frank Pepermans
    @rafaelcorbellini-egsys Streams by design only become active after an initial subscription, doOnX would then be a good choice like you mentioned.
    Frank Pepermans
    @jackdreilly since rxdart is built upon the Dart Streams, a ValueStream is like a broadcast Stream, see https://api.flutter.dev/flutter/dart-async/StreamController/StreamController.broadcast.html
    So no, to prevent onCancel, a dummy listener could be a solution in your case
    Jack Reilly
    @frankpepermans thanks for the help and the broadcast documentation, very helpful in understanding the motivation behind the behavior
    Can I use rxsubject without disposing it?
    Matias Meno
    When I have a ValueStream and I want to map the values, is there a convenient way to map to another ValueStream?
    Right now I'm using this:
    user.map((u) => u != null).shareValueSeeded(user.value != null)
    I just ended up writing custom extension for this
    Matias Meno
    @lizzardman yeah just doing the same
    I'm still being surprised by the behaviour of ValueStream :-/
    Like, you do this:
    newStream = old.map(mapping).shareValue(mapping);
    newStream.value == 'foo'; // That's not the case
    So, unless anyone is listening to the stream, it won't update .value properly
    Matias Meno
    I know it's not really rxdarts fault, but it's still a common pitfall for me.
    Frank Pepermans
    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
    @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
    Without a listener? No, basically everything triggers upon onListen internally
    Matias Meno
    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)
    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
    Is there an elegant way to handle this issue with rxdart?
    Frank Pepermans
    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
    @enyo Trying use throttleTime(leading: true, trailing: true) 😂
    Matias Meno
    @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
    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);
            .switchMap((_) => onValid)
            .switchMap((canSubmit) => canSubmit ? onSubmit : Stream.value(false));
    Matias Meno
    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
    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.