deep-kernel
Version:
DEEP Kernel Library
134 lines (100 loc) • 4.31 kB
JavaScript
/**
* Created by AlexanderC on 3/7/16.
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.KernelDriver = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _AbstractDriver2 = require('./AbstractDriver');
var _ComplexDriver = require('./ComplexDriver');
var _ScopeDriver = require('./ScopeDriver');
var _FsDriver = require('./FsDriver');
var _HttpDriver = require('./HttpDriver');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
let KernelDriver = exports.KernelDriver = function (_AbstractDriver) {
_inherits(KernelDriver, _AbstractDriver);
/**
* @param {Kernel|*} kernel
* @param {String} scopeKey
* @param {String} configFile
*/
function KernelDriver(kernel) {
let scopeKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : KernelDriver.SCOPE_KEY;
let configFile = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : KernelDriver.DEFAULT_CONFIG_FILE;
_classCallCheck(this, KernelDriver);
var _this = _possibleConstructorReturn(this, (KernelDriver.__proto__ || Object.getPrototypeOf(KernelDriver)).call(this));
_this._kernel = kernel;
_this._scopeKey = scopeKey;
_this._configFile = configFile;
return _this;
}
/**
* @returns {String|*}
*/
_createClass(KernelDriver, [{
key: '_load',
/**
* @param {String} scopeKey
* @param {String} configFile
* @private
*/
value: function _load() {
let scopeKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
let configFile = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
this._scopeKey = scopeKey || this._scopeKey;
this._configFile = configFile || this._configFile;
new _ComplexDriver.ComplexDriver().inherit(this).add(new _ScopeDriver.ScopeDriver(this._scopeKey).setScope(this._globalScope)).add(this._kernel.isBackend ? new _FsDriver.FsDriver(this._configFile) : new _HttpDriver.HttpDriver(this._configFile, true)).load();
}
/**
* @returns {Object}
* @private
*/
}, {
key: 'scopeKey',
get: function get() {
return this._scopeKey;
}
/**
* @returns {String|*}
*/
}, {
key: 'configFile',
get: function get() {
return this._configFile;
}
/**
* @returns {Kernel|*}
*/
}, {
key: 'kernel',
get: function get() {
return this._kernel;
}
}, {
key: '_globalScope',
get: function get() {
return this._kernel.isBackend ? global : window || {};
}
/**
* @returns {String}
*/
}], [{
key: 'SCOPE_KEY',
get: function get() {
return '__DEEP_CFG__';
}
/**
* @returns {String}
*/
}, {
key: 'DEFAULT_CONFIG_FILE',
get: function get() {
return '_config.json';
}
}]);
return KernelDriver;
}(_AbstractDriver2.AbstractDriver);