smartsystem/dist/index.js

51 lines
3.1 KiB
JavaScript
Raw Normal View History

2016-10-11 23:41:30 +00:00
"use strict";
2016-10-12 12:07:54 +00:00
require("typings-global");
2016-10-11 23:41:30 +00:00
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:07:54 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBRXZCLHVCQUFzQjtBQUN0Qiw2QkFBK0I7QUFDL0IsSUFBSSxRQUFRLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUFBO0FBRWx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