ValueStream
:-/
newStream = old.map(mapping).shareValue(mapping);
old.add('foo');
newStream.value == 'foo'; // That's not the case
.value
properly
EmailChanged
and PasswordChanged
events)
final debounced = events
.where((event) => event is! FormSubmitted)
.debounceTime(const Duration(milliseconds: 300));
FormSubmitted
event like this:
return events
.where((event) => event is FormSubmitted)
.mergeWith([debounced])
EmailChanged
and PasswordChanged
events could be triggered, being debounced, and then the FormSubmitted
event could arrive, and be handled before the change events are being handled
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));
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>>{},
);
}
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>>{},
);
}
BehaviorSubject
you can use the .add(value)
method