A TypeScript library for interacting with the system it's running on, including environment, network, and hardware information.
dist | ||
test | ||
ts | ||
.gitignore | ||
.gitlab-ci.yml | ||
npmextra.json | ||
package.json | ||
README.md | ||
tslint.json |
smartsystem
simplifies lazy loading with TypeScript
Availabililty
Status for master
Usage
We recommend the use of TypeScript for best Intellisense
smartsystem supports both npm and SystemJs as module loader.
import { LazyModule } from 'smartsystem'
import * as _myPlugin from 'myPlugin' // plugin does not get loaded here at runtime
let myPluginLazy = new LazyModule<typeof _myPlugin>('myPlugin')
myPluginLazy.setLoader('npm') // sets the loader, defaults to npm anyway
import * as _anotherPlugin from 'anotherPlugin' // plugin does not get loaded here at runtime
let anotherPluginLazy = new LazyModule<typeof _anotherPlugin>('anotherPlugin')
anotherPluginLazy.setLoader('systemjs') // sets the loader to systemjs
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 */
})