-
-
Save boeledi/6e10cea357472049d6079cb8ec7b12aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegistrationFormBloc extends Object with EmailValidator, PasswordValidator implements BlocBase { | |
final BehaviorSubject<String> _emailController = BehaviorSubject<String>(); | |
final BehaviorSubject<String> _passwordController = BehaviorSubject<String>(); | |
final BehaviorSubject<String> _passwordConfirmController = BehaviorSubject<String>(); | |
// | |
// Inputs | |
// | |
Function(String) get onEmailChanged => _emailController.sink.add; | |
Function(String) get onPasswordChanged => _passwordController.sink.add; | |
Function(String) get onRetypePasswordChanged => _passwordConfirmController.sink.add; | |
// | |
// Validators | |
// | |
Stream<String> get email => _emailController.stream.transform(validateEmail); | |
Stream<String> get password => _passwordController.stream.transform(validatePassword); | |
Stream<String> get confirmPassword => _passwordConfirmController.stream.transform(validatePassword) | |
.doOnData((String c){ | |
// If the password is accepted (after validation of the rules) | |
// we need to ensure both password and retyped password match | |
if (0 != _passwordController.value.compareTo(c)){ | |
// If they do not match, add an error | |
_passwordConfirmController.addError("No Match"); | |
} | |
}); | |
// | |
// Registration button | |
Stream<bool> get registerValid => Rx.combineLatest3<String, String, String, bool>( | |
email, | |
password, | |
confirmPassword, | |
(e, p, c) => true | |
); | |
@override | |
void dispose() { | |
_emailController.close(); | |
_passwordController.close(); | |
_passwordConfirmController.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment