smartsystem/README.md

65 lines
3.2 KiB
Markdown
Raw Normal View History

2016-10-06 17:28:00 +00:00
# smartsystem
simplifies lazy loading with TypeScript
## Availabililty
2017-05-13 08:33:34 +00:00
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartsystem)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartsystem)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartsystem)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartsystem/)
2016-10-06 17:28:00 +00:00
## Status for master
2017-05-13 08:33:34 +00:00
[![build status](https://GitLab.com/pushrocks/smartsystem/badges/master/build.svg)](https://GitLab.com/pushrocks/smartsystem/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartsystem/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartsystem/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartsystem.svg)](https://www.npmjs.com/package/smartsystem)
2016-10-06 17:28:00 +00:00
[![Dependency Status](https://david-dm.org/pushrocks/smartsystem.svg)](https://david-dm.org/pushrocks/smartsystem)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartsystem/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartsystem/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartsystem/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartsystem)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
We recommend the use of TypeScript for best Intellisense
2016-10-14 01:27:52 +00:00
smartsystem supports both npm and SystemJs as module loader.
2016-12-10 21:12:24 +00:00
```javascript
2016-10-12 12:01:15 +00:00
import { LazyModule } from 'smartsystem'
2016-10-06 17:28:00 +00:00
2017-05-13 08:33:34 +00:00
// plugin does not get loaded here at runtime
import * as _myPlugin from 'myPlugin'
2016-10-06 17:28:00 +00:00
2017-05-13 08:33:34 +00:00
// define the lazy module
let myLazyModule = new LazyModule<typeof _myPlugin>('myPlugin', __dirname)
// set the loader, defaults to npm anyway, can be systemjs alternatively
myLazyModule.setLoader('npm')
// another plugin
2016-10-12 12:09:58 +00:00
import * as _anotherPlugin from 'anotherPlugin' // plugin does not get loaded here at runtime
2017-05-13 08:33:34 +00:00
// define lazy module
let anotherLazyModule = new LazyModule<typeof _anotherPlugin>('anotherPlugin', __dirname)
2016-10-14 02:08:38 +00:00
anotherPluginLazy.setLoader('systemjs') // sets the loader to systemjs
2016-10-06 17:28:00 +00:00
2017-05-13 08:33:34 +00:00
myLazyModule.whenLoaded.then(myPlugin => {
2016-10-12 12:01:15 +00:00
/* 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 */
})
2017-05-13 08:33:34 +00:00
myLazyModule.load().then(myPlugin => {
2016-10-12 12:01:15 +00:00
/* do something with myPlugin.
myPlugin receives the typings flow from LazyModule class
This DOES LOAD the module */
})
2016-12-11 10:00:58 +00:00
```
2017-05-13 08:33:34 +00:00
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)