Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit e1d75b7

Browse files
Trying to simplify the observable
1 parent 8e5cb66 commit e1d75b7

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

src/GitHub.UI/Controls/AutoCompleteBox/AutoCompleteBox.cs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ void UpdateTextBox(IAutoCompleteTextInput value)
632632
if (textInput != null)
633633
{
634634
UnsubscribeToEvent("SelectionChanged");
635-
// UnsubscribeToEvent("OnTextBoxTextChanged");
635+
UnsubscribeToEvent("OnTextBoxTextChanged");
636636
}
637637

638638
textInput = value;
@@ -646,18 +646,18 @@ void UpdateTextBox(IAutoCompleteTextInput value)
646646
supportsShortcutOriginalValue = shortcutContainer.SupportsKeyboardShortcuts;
647647
}
648648

649-
// SubscribeToEvent("OnTextBoxTextChanged", ObserveTextBoxChanges()
650-
// .Subscribe(shouldPopulate =>
651-
// {
652-
// if (shouldPopulate)
653-
// {
654-
// PopulateDropDown();
655-
// }
656-
// else
657-
// {
658-
// DismissDropDown();
659-
// }
660-
// }));
649+
SubscribeToEvent("OnTextBoxTextChanged",
650+
ObserveTextBoxChanges().Subscribe(shouldPopulate =>
651+
{
652+
if (shouldPopulate)
653+
{
654+
PopulateDropDown();
655+
}
656+
else
657+
{
658+
DismissDropDown();
659+
}
660+
}));
661661

662662
if (Text != null)
663663
{
@@ -668,30 +668,37 @@ void UpdateTextBox(IAutoCompleteTextInput value)
668668

669669
IObservable<bool> ObserveTextBoxChanges()
670670
{
671-
var distinctTextChanges = textInput
671+
return textInput
672672
.TextChanged
673-
.Select(_ => textInput.Text ?? "")
674-
.DistinctUntilChanged();
675-
676-
if (MinimumPopulateDelay >= 0)
677-
{
678-
distinctTextChanges = distinctTextChanges
679-
.Throttle(TimeSpan.FromMilliseconds(MinimumPopulateDelay), RxApp.MainThreadScheduler);
680-
}
681-
682-
return distinctTextChanges
683-
.Select(text => {
684-
bool userChangedTextBox = ignoreTextPropertyChange == 0;
685-
if (ignoreTextPropertyChange > 0) ignoreTextPropertyChange--;
686-
687-
return new { Text = text, ShouldPopulate = text.Length > 0 && userChangedTextBox };
688-
})
689-
.Do(textInfo =>
673+
.Select(args =>
690674
{
691-
userCalledPopulate = textInfo.ShouldPopulate;
692-
UpdateAutoCompleteTextValue(textInfo.Text);
693-
})
694-
.Select(textInfo => textInfo.ShouldPopulate);
675+
return true;
676+
});
677+
678+
// var distinctTextChanges = textInput
679+
// .TextChanged
680+
// .Select(_ => textInput.Text ?? "")
681+
// .DistinctUntilChanged();
682+
//
683+
// if (MinimumPopulateDelay >= 0)
684+
// {
685+
// distinctTextChanges = distinctTextChanges
686+
// .Throttle(TimeSpan.FromMilliseconds(MinimumPopulateDelay), RxApp.MainThreadScheduler);
687+
// }
688+
//
689+
// return distinctTextChanges
690+
// .Select(text => {
691+
// bool userChangedTextBox = ignoreTextPropertyChange == 0;
692+
// if (ignoreTextPropertyChange > 0) ignoreTextPropertyChange--;
693+
//
694+
// return new { Text = text, ShouldPopulate = text.Length > 0 && userChangedTextBox };
695+
// })
696+
// .Do(textInfo =>
697+
// {
698+
// userCalledPopulate = textInfo.ShouldPopulate;
699+
// UpdateAutoCompleteTextValue(textInfo.Text);
700+
// })
701+
// .Select(textInfo => textInfo.ShouldPopulate);
695702
}
696703

697704
/// <summary>

0 commit comments

Comments
 (0)