feat(*): add debounce - #49
Open
ZnPdCo wants to merge 2 commits into
Open
Conversation
Member
|
@ZnPdCo 还没看代码,现在是无脑全禁enter了吗?maybe是改成,只有在还有inflight的请求的情况下,才禁用enter会更好一点? |
Author
那这样看起来要大改了,或者有比较丑陋的方式:每次enter后判断一个全局变量表示是否还在加载。 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
研究了一下前端搜索的 bug,主要有下:
fwt,会有两次请求,一次是fw,返回访问有关的词条,第二次是fwt,就是正常的fwt。因为要请求搜索服务器,所以会慢一点,而且顺序不分先后,很大概率会直接返回fw——访问的词条。所以这个 pr 修改了两个地方。一个是添加了输入框防抖;另一个是禁用了
enter默认是选择最优项(可以用上下键选择之后再 enter),这是因为有人搜索习惯性输入一个词之后直接 enter,那这样防抖也没办法处理,肯定会访问错误的页面,服务器返回的速度肯定赶不上 enter 的速度,所以就把这个快捷键 ban 掉了。当然,实现非常丑陋。禁用
enter这个是直接将对应代码注释了;而输入框防抖改起来太难了,我研究了很久都改不掉 😫,现在的处理方式是添加一个最先执行的脚本 hook 住 addEventListener,再往搜索框添加keyup事件时会下一个钩子:要防抖之后才能执行。如果有更好的改法,欢迎交流 ❤️。