Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DynamicModuleLoader<S>

Dynamic load modules by string types

example
  import { DynamicModuleLoader } from '@21epub/dynamic-loader'

  const loaders = [
      {
         modules: ["module1", "module2"],
         loader: async () => {
               await import('url/to/module1');
               await import('url/to/module2')
         }
      },
      {
         modules: 'module3',
         loader: async () => {
               await import('url/to/module3');
         }
      }
  ]

  const dynamicLoader = new DynamicModuleLoader(loaders)

You can also register other loaders after init

  dynamicLoader.register(['module4'], async () => {
      await import('url/to/module4')
  })

Load modules whenever in need (callbacks are module returns )

Return data should be considered by your async function

  dynamicLoader.loadAll().then( callbacks =>  console.log(callbacks))

Load specific module as you wish

  dynamicLoader.load(['module1','module2']).then(callbacks => console.log(callbacks ))

Type parameters

Hierarchy

  • DynamicModuleLoader

Index

Constructors

constructor

Methods

get

  • get(module: string): any
  • get a returned data for a specified module Undefined when this module has not finish loading

    Parameters

    • module: string

    Returns any

getLoadList

load

  • load(moduleOrModules: string | string[]): Promise<any>
  • Load one or mutiple modules

    Parameters

    • moduleOrModules: string | string[]

    Returns Promise<any>

loadAll

  • loadAll(): Promise<any>
  • Load All the modules that have been registered or initialized by this ModuleLoader

    Returns Promise<any>

register

  • register<T>(moduleOrModules: string | string[], promiseFn: T): void
  • Register one or mutiple lazyload module

    Type parameters

    Parameters

    • moduleOrModules: string | string[]
    • promiseFn: T

    Returns void

Generated using TypeDoc