From fbb2b946a67391f88b314d1575c21c4e4f962b53 Mon Sep 17 00:00:00 2001 From: alexiscatnip Date: Thu, 4 Aug 2022 22:19:28 +0800 Subject: [PATCH] refactor: #20 add automatic dispose to LoginPresenter unirx: .AddTo(this) will automatically Dispose when a GameObject is destroyed --- Assets/Raindrop/UI/Login/LoginPresenter.cs | 38 ++++++++++++++-------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Assets/Raindrop/UI/Login/LoginPresenter.cs b/Assets/Raindrop/UI/Login/LoginPresenter.cs index 3284309..db1c1e3 100644 --- a/Assets/Raindrop/UI/Login/LoginPresenter.cs +++ b/Assets/Raindrop/UI/Login/LoginPresenter.cs @@ -69,32 +69,42 @@ namespace Raindrop.UI.Login private void HookupUIEvents() { - LoginButton.onClick.AsObservable().Subscribe(_ => OnLoginBtnClick()); + LoginButton.onClick.AsObservable() + .Subscribe(_ => OnLoginBtnClick()) + .AddTo(this); loginButtonIsClickable.AsObservable() .Subscribe(_ => { SetLoginButtonVisibilty(_); - }); //update the login button availabilty according to this boolean. + }) + .AddTo(this); //update the login button availabilty according to this boolean. - usernameField.onValueChanged.AsObservable().Subscribe(_ => - { - Username = _; - credParserErrorString.Value = ""; - }); //change username property. - passwordField.onValueChanged.AsObservable().Subscribe(_ => - { - Password = _; + usernameField.onValueChanged.AsObservable() + .Subscribe(_ => + { + Username = _; + credParserErrorString.Value = ""; + }) + .AddTo(this); //change username property. + passwordField.onValueChanged.AsObservable() + .Subscribe(_ => + { + Password = _; - credParserErrorString.Value = ""; - }); //change password. + credParserErrorString.Value = ""; + }) + .AddTo(this); //change password. TOSCheckbox.OnValueChangedAsObservable() - .Subscribe(_ => agreeTOS = _); //when toggle checkbox, set boolean to the same value as the toggle-state + .Subscribe(_ => agreeTOS = _) + .AddTo(this); //when toggle checkbox, set boolean to the same value as the toggle-state //loginMsg.AsObservable().Where(_ => ! _.Equals("")).Subscribe(_ => UpdateLoginModalContent("Logging in process...", _)); - credParserErrorString.AsObservable().Subscribe(_ => OnCredParseError(_)); + credParserErrorString.AsObservable() + .Subscribe(_ => OnCredParseError(_)) + .AddTo(this); //gridDropdown.OnValueChangedAsObservable().Subscribe(_ => gridSelectedItem = _); //customURLCheckbox.onValueChanged.AsObservable().Subscribe(_ => cbCustomURL = _); //change username property.