Skip to main content

Interface: ILoaderStrategy<T>

An abstracted loader strategy interface.

Type parameters

NameType
Textends Piece

Implemented by

Methods

filter

โ–ธ filter(path): FilterResult

Retrieves the name and the extension of the specified file path.

example

// ts-node support
class MyStrategy extends LoaderStrategy {
filter(path) {
const extension = extname(path);
if (!['.js', '.ts'].includes(extension)) return null;
const name = basename(path, extension);
return { extension, name };
}
}

Parameters

NameTypeDescription
pathstringThe path of the file to be processed.

Returns

FilterResult

A ModuleData on success, otherwise null to stop the store from processing the path.

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:81


load

โ–ธ load(store, file): ILoaderResult<T>

The load hook, use this to override the loader.

example

class MyStrategy extends LoaderStrategy {
load(store, file) {
// ...
}
}

Parameters

NameType
storeStore<T>
fileHydratedModuleData

Returns

ILoaderResult<T>

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:117


onError

โ–ธ onError(error, path): void

Parameters

NameTypeDescription
errorErrorThe error that was thrown.
pathstringThe path of the file that caused the error to be thrown.

Returns

void

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:149


onLoad

โ–ธ onLoad(store, piece): unknown

Called after a piece has been loaded, but before Piece.onLoad and Store.set.

Parameters

NameTypeDescription
storeStore<T>The store that holds the piece.
pieceTThe piece that was loaded.

Returns

unknown

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:124


onLoadAll

โ–ธ onLoadAll(store): unknown

Called after all pieces have been loaded.

Parameters

NameTypeDescription
storeStore<T>The store that loaded all pieces.

Returns

unknown

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:130


onUnload

โ–ธ onUnload(store, piece): unknown

Called after a piece has been unloaded or overwritten by a newly loaded piece.

Parameters

NameTypeDescription
storeStore<T>The store that held the piece.
pieceTThe piece that was unloaded.

Returns

unknown

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:137


onUnloadAll

โ–ธ onUnloadAll(store): unknown

Called after all pieces have been unloaded.

Parameters

NameTypeDescription
storeStore<T>The store that unloaded all pieces.

Returns

unknown

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:143


preload

โ–ธ preload(file): PreloadResult<T>

The pre-load hook, use this to override the loader.

example

// CommonJS support:
class MyStrategy extends LoaderStrategy {
preload(path) {
return require(path);
}
}

example

// ESM support:
class MyStrategy extends LoaderStrategy {
preload(file) {
return import(file.path);
}
}

Parameters

NameType
fileModuleData

Returns

PreloadResult<T>

Defined in

projects/pieces/src/lib/strategies/ILoaderStrategy.ts:104