Class: LoaderStrategy<T>
A multi-purpose feature-complete loader strategy supporting multi-piece modules as well as supporting both ECMAScript Modules and CommonJS with reloading support.
Type parameters
Name | Type |
---|---|
T | extends Piece |
Implements
Constructors
constructor
• new LoaderStrategy<T
>(): LoaderStrategy
<T
>
Type parameters
Name | Type |
---|---|
T | extends Piece <PieceOptions , never > |
Returns
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:30
Properties
clientUsesESModules
• clientUsesESModules: boolean
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:26
filterDtsFiles
• Private
Readonly
filterDtsFiles: boolean
= false
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:28
supportedExtensions
• supportedExtensions: string
[]
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:27
Methods
filter
▸ filter(path
): FilterResult
Retrieves the name and the extension of the specified file path.
Parameters
Name | Type | Description |
---|---|---|
path | string | The path of the file to be processed. |
Returns
A ModuleData on success, otherwise null
to stop the store from processing the 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 };
}
}
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:55
load
▸ load(store
, file
): ILoaderResult
<T
>
The load hook, use this to override the loader.
Parameters
Name | Type |
---|---|
store | Store <T , never > |
file | HydratedModuleData |
Returns
Example
class MyStrategy extends LoaderStrategy {
load(store, file) {
// ...
}
}
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:86
onError
▸ onError(error
, path
): void
Parameters
Name | Type | Description |
---|---|---|
error | Error | The error that was thrown. |
path | string | The path of the file that caused the error to be thrown. |
Returns
void
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:129
onLoad
▸ onLoad(store
, piece
): unknown
Called after a piece has been loaded, but before Piece.onLoad and Store.set.
Parameters
Name | Type | Description |
---|---|---|
store | Store <T , never > | The store that holds the piece. |
piece | T | The piece that was loaded. |
Returns
unknown
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:109
onLoadAll
▸ onLoadAll(store
): unknown
Called after all pieces have been loaded.
Parameters
Name | Type | Description |
---|---|---|
store | Store <T , never > | The store that loaded all pieces. |
Returns
unknown
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:114
onUnload
▸ onUnload(store
, piece
): unknown
Called after a piece has been unloaded or overwritten by a newly loaded piece.
Parameters
Name | Type | Description |
---|---|---|
store | Store <T , never > | The store that held the piece. |
piece | T | The piece that was unloaded. |
Returns
unknown
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:119
onUnloadAll
▸ onUnloadAll(store
): unknown
Called after all pieces have been unloaded.
Parameters
Name | Type | Description |
---|---|---|
store | Store <T , never > | The store that unloaded all pieces. |
Returns
unknown
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:124
preload
▸ preload(file
): AsyncPreloadResult
<T
>
The pre-load hook, use this to override the loader.
Parameters
Name | Type |
---|---|
file | ModuleData |
Returns
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);
}
}
Implementation of
Defined in
projects/pieces/src/lib/strategies/LoaderStrategy.ts:70
walk
▸ walk(store
, path
, logger?
): AsyncIterableIterator
<string
>
Walks the specified path and returns an async iterator of all the files' paths.
Parameters
Name | Type | Description |
---|---|---|
store | Store <T , never > | The store that is walking the path. |
path | string | The path to recursively walk. |
logger? | null | StoreLogger | The logger to use when walking the path, if any. |
Returns
AsyncIterableIterator
<string
>