Create lazy module that enqueue calls while the original module is loading and dequeue calls when it is loaded.
yarn add create-lazy-module
import { createLazyModule } from 'create-lazy-module';
const loadOriginalModule = () => import('./analytics');
const methodNames = ['track'];
const [lazyModule, loadModule] = createLazyModule(
loadOriginalModule,
methodNames
);
loadOriginalModule
:() => Promise<OriginalModule>
, Returns a Promise resolving with the original module.methodNames
:string[]
, Methods that are available on the lazy module.
lazyModule
:LazyModule
, Lazy module with methods defined inmethodNames
.loadModule
:() => Promise<void>
, Loads the original module and dequeue calls.