2016-10-06 19:28:00 +02:00
|
|
|
# smartsystem
|
|
|
|
simplifies lazy loading with TypeScript
|
|
|
|
|
|
|
|
## Availabililty
|
|
|
|
[](https://www.npmjs.com/package/smartsystem)
|
|
|
|
[](https://gitlab.com/pushrocks/smartsystem)
|
|
|
|
[](https://github.com/pushrocks/smartsystem)
|
|
|
|
[](https://pushrocks.gitlab.io/smartsystem/)
|
|
|
|
|
|
|
|
## Status for master
|
|
|
|
[](https://gitlab.com/pushrocks/smartsystem/commits/master)
|
|
|
|
[](https://gitlab.com/pushrocks/smartsystem/commits/master)
|
|
|
|
[](https://david-dm.org/pushrocks/smartsystem)
|
|
|
|
[](https://www.bithound.io/github/pushrocks/smartsystem/master/dependencies/npm)
|
|
|
|
[](https://www.bithound.io/github/pushrocks/smartsystem)
|
|
|
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
|
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
|
|
[](http://standardjs.com/)
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
We recommend the use of TypeScript for best Intellisense
|
|
|
|
|
|
|
|
```typescript
|
2016-10-12 14:01:15 +02:00
|
|
|
import { LazyModule } from 'smartsystem'
|
2016-10-06 19:28:00 +02:00
|
|
|
|
2016-10-12 14:09:58 +02:00
|
|
|
import * as _myPlugin from 'myPlugin' // plugin does not get loaded here at runtime
|
|
|
|
let myPluginLazy = new LazyModule<typeof _myPlugin>('myPlugin')
|
2016-10-06 19:28:00 +02:00
|
|
|
|
2016-10-12 14:09:58 +02:00
|
|
|
import * as _anotherPlugin from 'anotherPlugin' // plugin does not get loaded here at runtime
|
2016-10-12 14:15:27 +02:00
|
|
|
let anotherPluginLazy = new LazyModule<typeof _anotherPlugin>('anotherPlugin')
|
2016-10-06 19:28:00 +02:00
|
|
|
|
2016-10-12 14:01:15 +02:00
|
|
|
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 */
|
|
|
|
})
|
2016-10-06 19:28:00 +02:00
|
|
|
```
|