Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 插件市场搜索框使用防抖函数 #130

Closed
idranme opened this issue Mar 18, 2023 · 3 comments
Closed

Feature: 插件市场搜索框使用防抖函数 #130

idranme opened this issue Mar 18, 2023 · 3 comments

Comments

@idranme
Copy link
Contributor

idranme commented Mar 18, 2023

当前版本在输入内容时会有些卡顿,因此建议使用防抖函数以减少触发次数。

关于防抖函数的实现,new Bing 这样说:

// 基于时间戳的实现
function debounce(fn, delay) {
  let timeout = null;
  return function () {
    let context = this;
    let args = arguments;
    let now = +new Date();
    if (timeout && now < timeout) {
      clearTimeout(timeout);
    }
    timeout = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  };
}

// 基于定时器的实现
function debounce(fn, delay) {
  let timeout = null;
  return function () {
    let context = this;
    let args = arguments;
    if (timeout) {
      clearTimeout(timeout);
    }
    timeout = setTimeout(function () {
      fn.apply(context, args);
    }, delay);
  };
}
@shigma
Copy link
Member

shigma commented Mar 18, 2023

使用防抖无法解决搜索的问题。目前部分环境下单独输入一个字符也足以上浏览器卡死。

duplicate of #55

@idranme
Copy link
Contributor Author

idranme commented Mar 18, 2023

使用防抖无法解决搜索的问题。目前部分环境下单独输入一个字符也足以上浏览器卡死。

duplicate of #55

不过应该可以解决输入不跟手的问题(输入的字符串的显示存在延迟)。

@shigma
Copy link
Member

shigma commented Mar 18, 2023

有点道理。

@shigma shigma closed this as completed in 8bffbf3 May 17, 2023
CyanChanges pushed a commit to CyanForks/webui that referenced this issue Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants