1.0.1 • Published 3 years ago

create-lazy-module v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

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.