Skip to content

Commit fcca114

Browse files
authored
fix: make virtual pieces respect name restrictions like normal pieces (#374)
1 parent 8a0bced commit fcca114

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/lib/structures/Store.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRe
6161
/**
6262
* The queue of manually registered pieces to load.
6363
*/
64-
private readonly [ManuallyRegisteredPiecesSymbol]: StoreManuallyRegisteredPiece<StoreName>[] = [];
64+
private readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();
6565

6666
/**
6767
* Whether or not the store has called `loadAll` at least once.
@@ -161,7 +161,7 @@ export class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRe
161161
throw new LoaderError(LoaderErrorType.IncorrectType, `The piece ${entry.name} does not extend ${this.name}`);
162162
}
163163

164-
this[ManuallyRegisteredPiecesSymbol].push(entry);
164+
this[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);
165165
if (this.#calledLoadAll) {
166166
const piece = this.construct(entry.piece as unknown as Constructor<T>, {
167167
name: entry.name,
@@ -242,7 +242,7 @@ export class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRe
242242
this.#calledLoadAll = true;
243243

244244
const pieces: T[] = [];
245-
for (const entry of this[ManuallyRegisteredPiecesSymbol]) {
245+
for (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {
246246
const piece = this.construct(entry.piece as unknown as Constructor<T>, {
247247
name: entry.name,
248248
root: VirtualPath,

src/lib/structures/StoreRegistry.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ export class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryVal
108108
// If there was a queue for this store, add it to the store and delete the queue:
109109
const queue = this.#pendingManuallyRegisteredPieces.get(store.name);
110110
if (queue) {
111-
store[ManuallyRegisteredPiecesSymbol].push(...queue);
111+
for (const entry of queue) {
112+
store[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);
113+
}
114+
112115
this.#pendingManuallyRegisteredPieces.delete(store.name);
113116
}
114117

0 commit comments

Comments
 (0)