Open t9md opened 6 years ago
I think ideally, for performance reasons, we would never invoke onDidChangeText
listeners unless the text actually changed. But in your abc
example, we would have to do an extra string comparison to detect a no-op change, so it is probably not worth it.
So I guess I am happy with the current behavior. How bad is the breakage in the atom-select-list
specs?
Not sure other breakage are exist.
Found command-palette use SelectListView.prototype.reset
here.
IMO, its better to fire did-change-text
regardless of old and new text.
selectListView.reset()
is common pattern and it's easy to overlook to notice this caveat(only empty-to-empty case is not fired).Can you explain a case where a package relies on onDidChangeText
listeners getting called even if the text did not change? I'm not quite understanding how your example about reset
necessarily relates to onDidChangeText
.
At least these core pkg calling selectListView.reset
not sure impact of each.
$ ag selectListView.reset
git-diff/lib/diff-list-view.js
44: this.selectListView.reset()
snippets/lib/snippets-available.js
51: this.selectListView.reset()
encoding-selector/lib/encoding-list-view.js
61: this.selectListView.reset()
grammar-selector/lib/grammar-list-view.js
59: this.selectListView.reset()
command-palette/lib/command-palette-view.js
111: this.selectListView.reset()
fuzzy-finder/lib/fuzzy-finder-view.js
168: this.selectListView.reset()
symbols-view/lib/symbols-view.js
188: this.selectListView.reset();
Can you explain a case where a package relies on onDidChangeText listeners getting called even if the text did not change? I'm not quite understanding how your example about reset necessarily relates to onDidChangeText.
queryEditor.onDidChange
event, result in call to didChangeQuery
didChangeQuery
eventually call prop.didChangeQuery
(if set by selectListView
's client pkg).Why I cannot answer how bad this change is prop.didChangeQuery
is set client pkg and impact is vary from client pkg.
So to make selectLisView compatible with old behavior, following workaround can be possible.
Old
reset () {
this.refs.queryEditor.setText('')
}
New
reset () {
if (this.refs.queryEditor.getText === "") {
this.didChangeQuery()
} else {
this.refs.queryEditor.setText('')
}
}
I still don't understand why we should call didChangeQuery
if the query did not change. What is the calling code that depends on didChangeQuery
being called even if the query was and remains empty?
This is body of didChangQuery(), it refresh rendered items by calling this.computeItems()
.
And if reset
is called launch time, it is expecting render fresh item by reset()
ting., but if reset()
no longer re-render items, it fail to gather newly added command in command-palette case.
I've not investigated well yet, so above explanation is just a though I simulated in my mind.
didChangeQuery () {
if (this.props.didChangeQuery) {
this.props.didChangeQuery(this.getFilterQuery())
}
this.computeItems()
}
I too not clearly understand how is actual bad impact by not calling onDidChange with empty to empty text. What I wanted to report is it introduce behavioral change in selectListView.reset
and investigating each impact like we should add workaround code or not is not what I wanted to do.
So asked if it's intentional.
Ok, I think I see what you're saying. Let me try to summarize. In atom-select-list
, SelectList.reset
is probably expected by packages (e.g. command-palette
) to always recompute the items. Before, this would automatically happened via a call to SelectList.didChangeQuery
. Now, it does not happen if the query was already blank.
I think it does make sense to change atom-select-list
in order to fix this. I would make a slight tweak to your New code:
reset () {
if (this.refs.queryEditor.getText === "") {
this.computeItems()
} else {
this.refs.queryEditor.setText('')
}
}
This way, we'll recompute the items but avoid calling the didChangeQuery
hook, because the query has not actually changed. Does that make sense?
Thanks for reporting this and determining the cause of the problem. I agree that if there's user-facing impact we need to fix it. It just took me a minute to understand the problem.
@maxbrunsfeld Your modification on reset
workaround code does make sense.
My original code is just trying to stupidly compatible with older behavior for less chance of breakage.
Your summarization is also correct. Thank you for understanding.
@maxbrunsfeld
After PR #274, empty("") to empty("") text change no longer fire
did-change-text
.This seems to be a bit confusing since non empty same text change still fire
did-change-text
(e.g. "abc" to "abc").And noticed this change breaks at least select-list's test-spec. Does this change intentional?
Impact
Some pkg feature assuming
editor.setText("")
always fireeditor.onDidChange
event, but this is no longer true after #274.assuming selectListView.reset() always fire event
But not fire when compactedChanges length become 0 in"" to "" change
At least I noticed select-list's spec was broken by this change here.
Reproduce