Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
feat: use throttling instead of debouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
gmenih committed May 19, 2018
1 parent 205b8f8 commit e8d30d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/background/omnibox.handlers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debounce from 'lodash/debounce';
import throttle from 'lodash/throttle';
import { isChrome } from '../browser';
import { SEARCH_DEBOUNCE, OPTION_STRINGS as OPTIONS } from '../constants';

Expand All @@ -22,8 +22,8 @@ const getTargetsFromSettings = (settings) => {
return targets;
};

export const onTextChangedFactory = (client, settings, { debounceTime = SEARCH_DEBOUNCE } = {}) =>
debounce(async (text, suggest) => {
export const onTextChangedFactory = (client, settings, { debounceTime = SEARCH_DEBOUNCE } = {}) => {
const throttledSearch = throttle(async (text, suggest) => {
const targets = getTargetsFromSettings(settings);
const searchForks = !!settings[OPTIONS.SEARCH_FORKED];
const userLogins = [];
Expand All @@ -46,6 +46,13 @@ export const onTextChangedFactory = (client, settings, { debounceTime = SEARCH_D
console.error(err);
}
}, debounceTime);
return (text, suggest) => {
if (text.length < 2) {
return;
}
throttledSearch(text, suggest);
};
};

export const onInputEnteredFactory = browser => (text, disposition) => {
const url = text.startsWith('https://')
Expand Down
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const GITHUB_API = 'https://api.github.com/graphql';
export const GITHUB_OAUTH_URL = 'https://github.com/login/oauth/authorize';
export const GITHUB_TOKEN_URL = 'https://github.com/login/oauth/access_token';
export const REDIRECT_URL = 'https://github.com/gmenih341/github-omnibox';
export const SEARCH_DEBOUNCE = 50;
export const SEARCH_DEBOUNCE = 200;
export const OPTION_STRINGS = {
GITHUB_TOKEN: '__github.token',
GITHUB_LOGINS: '__github.logins',
Expand Down

0 comments on commit e8d30d9

Please sign in to comment.