smartsystem/README.md
2016-10-12 14:09:58 +02:00

2.4 KiB

smartsystem

simplifies lazy loading with TypeScript

Availabililty

npm git git docs

Status for master

build status coverage report Dependency Status bitHound Dependencies bitHound Code TypeScript node JavaScript Style Guide

Usage

We recommend the use of TypeScript for best Intellisense

import { LazyModule } from 'smartsystem'

import * as _myPlugin from 'myPlugin' // plugin does not get loaded here at runtime
let myPluginLazy = new LazyModule<typeof _myPlugin>('myPlugin')

import * as _anotherPlugin from 'anotherPlugin' // plugin does not get loaded here at runtime
let anotherPluginPromised = LazyModule<typeof _anotherPlugin>('anotherPlugin')

myPluginLazy.whenLoaded.then(myPlugin => {
    /* do something with myPlugin. 
       myPlugin receives the typings flow from LazyModule class
       This does NOT load the module during runtime
       The promise whenLoaded will be resolved whenever load() is called for the first time */
})

myPluginLazy.load().then(myPlugin => {
    /* do something with myPlugin. 
       myPlugin receives the typings flow from LazyModule class
       This DOES LOAD the module */
})