inhabit-module-base
Advanced tools
Comparing version 1.0.3 to 1.1.0
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
/** | ||
* | ||
* @param configuration | ||
* @param dependencies | ||
* @constructor | ||
*/ | ||
function InhabitModuleBase(configuration, dependencies) { | ||
if (!configuration) { | ||
throw Error('No configuration presented.'); | ||
} | ||
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; }; }(); | ||
if (!dependencies) { | ||
throw Error('No dependencies presented.'); | ||
} | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; } | ||
this.configure(configuration).inject(dependencies); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
this.deferred = this.$.Deffered(); | ||
this.content = []; | ||
} | ||
/** | ||
* Inhabit Module Base class | ||
* Get Content | ||
* @returns {*} | ||
*/ | ||
var InhabitModuleBase = function () { | ||
InhabitModuleBase.prototype.getContent = function () { | ||
setTimeout(this.getDeliveryMethod(), 1); | ||
return this.deferred.promise(); | ||
}; | ||
/** | ||
* @constructor | ||
* @param configuration | ||
* @param dependencies {{$}, {handlebars}, {textClassificationService}, {searchEngineService}} | ||
*/ | ||
function InhabitModuleBase(configuration, dependencies) { | ||
_classCallCheck(this, InhabitModuleBase); | ||
/** | ||
* | ||
* @returns {boolean} | ||
*/ | ||
InhabitModuleBase.prototype.hasContent = function () { | ||
return !!this.content.length; | ||
}; | ||
if (!configuration) { | ||
throw Error('No configuration presented.'); | ||
} | ||
/** | ||
* Return a fetch method | ||
*/ | ||
InhabitModuleBase.prototype.getDeliveryMethod = function () { | ||
var deliveryMethod = this.configuration.deliveryMethod.name, | ||
deliveryParameters = this.configuration.deliveryMethod; | ||
if (!dependencies) { | ||
throw Error('No dependencies presented.'); | ||
} | ||
this.configure(configuration).inject(dependencies); | ||
this.deferred = this.$.Deffered(); | ||
this.content = []; | ||
if (typeof this[deliveryMethod] !== 'function') { | ||
throw Error('No such fetchMethod: ' + deliveryMethod); | ||
} | ||
/** | ||
* Start fetching content and return a promise | ||
* @returns {Promise} | ||
*/ | ||
return this[deliveryMethod].bind(this, deliveryParameters); | ||
}; | ||
/** | ||
* Store dependencies | ||
* @param dependencies | ||
* @returns {InhabitModuleBase} | ||
*/ | ||
InhabitModuleBase.prototype.inject = function (dependencies) { | ||
this.$ = dependencies.$; | ||
this.handlebars = dependencies.handlebars; | ||
this.textClassificationService = dependencies.textClassificationService; | ||
this.searchEngineService = dependencies.searchEngineService; | ||
_createClass(InhabitModuleBase, [{ | ||
key: 'getContent', | ||
value: function getContent() { | ||
this.fetch(); | ||
return this.deferred.promise(); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Return true if have | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* Configure | ||
* @param configuration | ||
*/ | ||
InhabitModuleBase.prototype.configure = function (configuration) { | ||
this.configuration = configuration; | ||
}, { | ||
key: 'hasContent', | ||
value: function hasContent() { | ||
return !!this.content.length; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Start async fetching | ||
*/ | ||
}, { | ||
key: 'fetch', | ||
value: function () { | ||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
var fetchMethod, fetchParameters; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
fetchMethod = this.configuration.deliveryMethod.name; | ||
fetchParameters = this.configuration.deliveryMethod; | ||
if (!(typeof this[fetchMethod] !== 'function')) { | ||
_context.next = 4; | ||
break; | ||
} | ||
throw Error('No such fetchMethod: ' + fetchMethod); | ||
case 4: | ||
// Execute a fetchMethod | ||
this[fetchMethod](fetchParameters); | ||
case 5: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function fetch() { | ||
return _ref.apply(this, arguments); | ||
} | ||
return fetch; | ||
}() | ||
/** | ||
* Store dependencies | ||
* @param dependencies | ||
* @returns {InhabitModuleBase} | ||
*/ | ||
}, { | ||
key: 'inject', | ||
value: function inject(dependencies) { | ||
this.$ = dependencies.$; | ||
this.handlebars = dependencies.handlebars; | ||
this.textClassificationService = dependencies.textClassificationService; | ||
this.searchEngineService = dependencies.searchEngineService; | ||
return this; | ||
} | ||
/** | ||
* Store configuration | ||
* @param configuration | ||
* @returns {InhabitModuleBase} | ||
*/ | ||
}, { | ||
key: 'configure', | ||
value: function configure(configuration) { | ||
this.configuration = configuration; | ||
return this; | ||
} | ||
}]); | ||
return InhabitModuleBase; | ||
}(); | ||
exports.default = InhabitModuleBase; | ||
module.exports = InhabitModuleBase; |
{ | ||
"name": "inhabit-module-base", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A Base Module class for InHabit.", | ||
@@ -5,0 +5,0 @@ "main": "build/InhabitModuleBase.js", |
@@ -34,3 +34,3 @@ /** | ||
function changeext(filename) { | ||
return path.basename(filename, '.es6') + '.js'; | ||
return path.basename(filename, path.extname(filename)) + '.js'; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
15
171
0
31966