Skip to content

Commit

Permalink
fix: make virtual pieces respect name restrictions like normal pieces (
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Jan 13, 2024
1 parent 8a0bced commit fcca114
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/lib/structures/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Store<T extends Piece, StoreName extends StoreRegistryKey = StoreRe
/**
* The queue of manually registered pieces to load.
*/
private readonly [ManuallyRegisteredPiecesSymbol]: StoreManuallyRegisteredPiece<StoreName>[] = [];
private readonly [ManuallyRegisteredPiecesSymbol] = new Map<string, StoreManuallyRegisteredPiece<StoreName>>();

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

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

const pieces: T[] = [];
for (const entry of this[ManuallyRegisteredPiecesSymbol]) {
for (const entry of this[ManuallyRegisteredPiecesSymbol].values()) {
const piece = this.construct(entry.piece as unknown as Constructor<T>, {
name: entry.name,
root: VirtualPath,
Expand Down
5 changes: 4 additions & 1 deletion src/lib/structures/StoreRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ export class StoreRegistry extends Collection<StoreRegistryKey, StoreRegistryVal
// If there was a queue for this store, add it to the store and delete the queue:
const queue = this.#pendingManuallyRegisteredPieces.get(store.name);
if (queue) {
store[ManuallyRegisteredPiecesSymbol].push(...queue);
for (const entry of queue) {
store[ManuallyRegisteredPiecesSymbol].set(entry.name, entry);
}

this.#pendingManuallyRegisteredPieces.delete(store.name);
}

Expand Down

0 comments on commit fcca114

Please sign in to comment.