smartsystem/dist/index.js

50 lines
3.1 KiB
JavaScript
Raw Normal View History

2016-10-11 23:41:30 +00:00
"use strict";
const q = require("q");
const lik_1 = require("lik");
let systemjs = require('systemjs');
class Smartsystem {
constructor() {
this.lazyModules = new lik_1.Objectmap();
}
/**
* add lazyModule to Smartsystem
*/
addLazyModule(lazyModuleArg) {
this.lazyModules.add(lazyModuleArg);
}
}
// create the internal smartsystem
let smartsystem = new Smartsystem();
/**
* defines a LazyModule
*/
class LazyModule {
constructor(nameArg, cwdArg = process.cwd()) {
this.name = nameArg;
this.cwd = cwdArg;
2016-10-12 12:01:15 +00:00
smartsystem.addLazyModule(this); // add module to smartsystem instance
this.nameIsPath = /\.\//.test(this.name); // figure out if name is path
this.whenLoadedDeferred = q.defer();
this.whenLoaded = this.whenLoadedDeferred.promise;
2016-10-11 23:41:30 +00:00
}
/**
* loads the module
*/
load() {
let done = q.defer();
let loadedModule;
systemjs.import(this.name).then((m) => {
loadedModule = m;
2016-10-12 12:01:15 +00:00
this.whenLoadedDeferred.resolve(loadedModule);
2016-10-11 23:41:30 +00:00
done.resolve(loadedModule);
2016-10-12 12:01:15 +00:00
}).catch(err => { console.log(err); });
2016-10-11 23:41:30 +00:00
return done.promise;
}
/**
* loads additional lazy modules specified as arguments and returns them in the promise for easy use
*/
loadAlso(...args) {
}
}
exports.LazyModule = LazyModule;
2016-10-12 12:01:15 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBRUEsdUJBQXNCO0FBQ3RCLDZCQUErQjtBQUMvQixJQUFJLFFBQVEsR0FBRyxPQUFPLENBQUMsVUFBVSxDQUFDLENBQUE7QUFFbEM7SUFBQTtRQUNJLGdCQUFXLEdBQUcsSUFBSSxlQUFTLEVBQW1CLENBQUE7SUFRbEQsQ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