Skip to content

Commit 63f73fe

Browse files
authored
feat(url): add a beta updateOnEveryKeystroke option (#1779)
Updating the url bar constantly may be a challenge for some OS + browsers (OSX, chrome), I want to push this option and see if it's better for users.
1 parent 88adda3 commit 63f73fe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lib/url-sync.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class URLSync {
9595
this.mapping = options.mapping || {};
9696
this.getHistoryState = options.getHistoryState || (() => null);
9797
this.threshold = options.threshold || 700;
98+
this.updateOnEveryKeyStroke = options.updateOnEveryKeyStroke || true;
9899
this.trackedParameters = options.trackedParameters || ['query', 'attribute:*', 'index', 'page', 'hitsPerPage'];
99100

100101
this.searchParametersFromUrl = AlgoliaSearchHelper
@@ -146,11 +147,19 @@ class URLSync {
146147
}
147148
);
148149

149-
if (this.timer() < this.threshold) {
150-
this.urlUtils.replaceState(qs, {getHistoryState: this.getHistoryState});
151-
} else {
152-
this.urlUtils.pushState(qs, {getHistoryState: this.getHistoryState});
150+
if (this.updateOnEveryKeyStroke === true) {
151+
if (this.timer() < this.threshold) {
152+
this.urlUtils.replaceState(qs, {getHistoryState: this.getHistoryState});
153+
} else {
154+
this.urlUtils.pushState(qs, {getHistoryState: this.getHistoryState});
155+
}
156+
return;
153157
}
158+
159+
clearTimeout(this.urlUpdateTimeout);
160+
this.urlUpdateTimeout = setTimeout(() => {
161+
this.urlUtils.pushState(qs, {getHistoryState: this.getHistoryState});
162+
}, this.threshold);
154163
}
155164

156165
// External API's

0 commit comments

Comments
 (0)