Skip to content

Create lazy module that enqueues calls while the original module is loading and dequeue calls when it is loaded.

License

Notifications You must be signed in to change notification settings

oliger/create-lazy-module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create Lazy Module

Create lazy module that enqueue calls while the original module is loading and dequeue calls when it is loaded.

Example

Installation

yarn add create-lazy-module

API

import { createLazyModule } from 'create-lazy-module';

const loadOriginalModule = () => import('./analytics');
const methodNames = ['track'];

const [lazyModule, loadModule] = createLazyModule(
  loadOriginalModule,
  methodNames
);

Parameters

  • loadOriginalModule: () => Promise<OriginalModule>, Returns a Promise resolving with the original module.
  • methodNames: string[], Methods that are available on the lazy module.

Return

  • lazyModule: LazyModule, Lazy module with methods defined in methodNames.
  • loadModule: () => Promise<void>, Loads the original module and dequeue calls.

About

Create lazy module that enqueues calls while the original module is loading and dequeue calls when it is loaded.

Resources

License

Stars

Watchers

Forks

Packages

No packages published