Skip to content

Commit 9c22028

Browse files
committed
Dependency injection searchState
1 parent 6407e5b commit 9c22028

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/librustdoc/html/static/js/search.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ class RoaringBitmapBits {
10971097

10981098

10991099
class DocSearch {
1100-
constructor(rawSearchIndex, rootPath) {
1100+
constructor(rawSearchIndex, rootPath, searchState) {
11011101
/**
11021102
* @type {Map<String, RoaringBitmap>}
11031103
*/
@@ -1119,6 +1119,7 @@ class DocSearch {
11191119
this.typeNameIdMap = new Map();
11201120
this.ALIASES = new Map();
11211121
this.rootPath = rootPath;
1122+
this.searchState = searchState;
11221123

11231124
/**
11241125
* Special type name IDs for searching by array.
@@ -1729,7 +1730,7 @@ class DocSearch {
17291730
}
17301731
}
17311732
currentIndex += itemTypes.length;
1732-
searchState.descShards.set(crate, descShardList);
1733+
this.searchState.descShards.set(crate, descShardList);
17331734
}
17341735
// Drop the (rather large) hash table used for reusing function items
17351736
this.TYPES_POOL = new Map();
@@ -2869,7 +2870,7 @@ class DocSearch {
28692870

28702871
const fetchDesc = alias => {
28712872
return this.searchIndexEmptyDesc.get(alias.crate).contains(alias.bitIndex) ?
2872-
"" : searchState.loadDesc(alias);
2873+
"" : this.searchState.loadDesc(alias);
28732874
};
28742875
const [crateDescs, descs] = await Promise.all([
28752876
Promise.all(crateAliases.map(fetchDesc)),
@@ -3302,7 +3303,7 @@ class DocSearch {
33023303
const descs = await Promise.all(list.map(result => {
33033304
return this.searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ?
33043305
"" :
3305-
searchState.loadDesc(result);
3306+
this.searchState.loadDesc(result);
33063307
}));
33073308
for (const [i, result] of list.entries()) {
33083309
result.desc = descs[i];
@@ -3903,9 +3904,9 @@ function updateCrate(ev) {
39033904
function initSearch(searchIndx) {
39043905
rawSearchIndex = searchIndx;
39053906
if (typeof window !== "undefined") {
3906-
docSearch = new DocSearch(rawSearchIndex, ROOT_PATH);
3907+
docSearch = new DocSearch(rawSearchIndex, ROOT_PATH, searchState);
39073908
} else if (typeof exports !== "undefined") {
3908-
docSearch = new DocSearch(rawSearchIndex, ROOT_PATH);
3909+
docSearch = new DocSearch(rawSearchIndex, ROOT_PATH, searchState);
39093910
exports.docSearch = docSearch;
39103911
exports.parseQuery = DocSearch.parseQuery;
39113912
}

0 commit comments

Comments
 (0)