From bda7ca3e828e518a2bf66f7e46a3e9c4d968bb71 Mon Sep 17 00:00:00 2001 From: Folyd Date: Sun, 23 Jun 2024 10:52:13 -0700 Subject: [PATCH] Dependency injection DocSearch's searchState --- extension/search/docs/base-v2.js | 11 +++++------ extension/search/docs/base.js | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/extension/search/docs/base-v2.js b/extension/search/docs/base-v2.js index 564a0df..54137c8 100644 --- a/extension/search/docs/base-v2.js +++ b/extension/search/docs/base-v2.js @@ -1,5 +1,3 @@ -import searchState from "./desc-shard.js"; - // polyfill // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced if (!Array.prototype.toSpliced) { @@ -1090,7 +1088,7 @@ class RoaringBitmapBits { export default class DocSearchV2 { - constructor(rawSearchIndex, rootPath) { + constructor(rawSearchIndex, rootPath, searchState) { /** * @type {Map} */ @@ -1112,6 +1110,7 @@ export default class DocSearchV2 { this.typeNameIdMap = new Map(); this.ALIASES = new Map(); this.rootPath = rootPath; + this.searchState = searchState; /** * Special type name IDs for searching by array. @@ -1722,7 +1721,7 @@ export default class DocSearchV2 { } } currentIndex += itemTypes.length; - searchState.descShards.set(crate, descShardList); + this.searchState.descShards.set(crate, descShardList); } // Drop the (rather large) hash table used for reusing function items this.TYPES_POOL = new Map(); @@ -2862,7 +2861,7 @@ export default class DocSearchV2 { const fetchDesc = alias => { return this.searchIndexEmptyDesc.get(alias.crate).contains(alias.bitIndex) ? - "" : searchState.loadDesc(alias); + "" : this.searchState.loadDesc(alias); }; const [crateDescs, descs] = await Promise.all([ Promise.all(crateAliases.map(fetchDesc)), @@ -3295,7 +3294,7 @@ export default class DocSearchV2 { const descs = await Promise.all(list.map(result => { return this.searchIndexEmptyDesc.get(result.crate).contains(result.bitIndex) ? "" : - searchState.loadDesc(result); + this.searchState.loadDesc(result); })); for (const [i, result] of list.entries()) { result.desc = descs[i]; diff --git a/extension/search/docs/base.js b/extension/search/docs/base.js index 5695079..3c5bbea 100644 --- a/extension/search/docs/base.js +++ b/extension/search/docs/base.js @@ -1,11 +1,11 @@ import DocSearchV2 from "./base-v2.js"; export default class DocSearch extends DocSearchV2 { - constructor(name, searchIndex, rootPath) { + constructor(name, searchIndex, rootPath, descShards) { if (!(searchIndex instanceof Map)) { searchIndex = new Map(Object.entries(searchIndex)); } - super(searchIndex, rootPath); + super(searchIndex, rootPath, descShards); this.name = name; }