inhabit-module-base
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -7,56 +7,56 @@ "use strict"; | ||
/** | ||
* setImmediate polyfill | ||
* @constructor | ||
* @param configuration | ||
* @param dependencies | ||
*/ | ||
(function (global) { | ||
if (!global.setImmediate) global.setImmediate = function () { | ||
var head = {}, | ||
tail = head; | ||
function InhabitModuleBase(configuration, dependencies) { | ||
if (!configuration) { | ||
throw Error('No configuration presented.'); | ||
} | ||
var ID = Math.random(); | ||
function onmessage(e) { | ||
if (e.data != ID) return; | ||
head = head.next; | ||
var func = head.func; | ||
delete head.func; | ||
func(); | ||
} | ||
if (!dependencies) { | ||
throw Error('No dependencies presented.'); | ||
} | ||
if (global.addEventListener) { | ||
// IE9+ | ||
global.addEventListener('message', onmessage); | ||
} else { | ||
// IE8 | ||
global.attachEvent('onmessage', onmessage); | ||
} | ||
this.configure(configuration).inject(dependencies); | ||
return function (func) { | ||
tail = tail.next = { func: func }; | ||
global.postMessage(ID, "*"); | ||
}; | ||
}(); | ||
})(global || window); | ||
this.name = this.constructor.name; | ||
this.deferred = this.$.Deferred(); | ||
} | ||
/** | ||
* | ||
* @param configuration | ||
* @param dependencies | ||
* @constructor | ||
* Start async task that fetches content and return a this.deffered.promise() | ||
* @returns {Promise} | ||
*/ | ||
function InhabitModuleBase(configuration, dependencies) { | ||
if (!configuration) { | ||
throw Error('No configuration presented.'); | ||
} | ||
InhabitModuleBase.prototype.getContent = mustBeOverrided; | ||
if (!dependencies) { | ||
throw Error('No dependencies presented.'); | ||
} | ||
/** | ||
* Return a Thumbnail URL | ||
* @returns {string} | ||
*/ | ||
InhabitModuleBase.prototype.getThumbnail = mustBeOverrided; | ||
this.configure(configuration).inject(dependencies); | ||
/** | ||
* Return a Title | ||
* @returns {string} | ||
*/ | ||
InhabitModuleBase.prototype.getTitle = mustBeOverrided; | ||
this.name = this.constructor.name; | ||
this.deferred = this.$.Deferred(); | ||
this.content = []; | ||
} | ||
/** | ||
* @returns {boolean} | ||
*/ | ||
InhabitModuleBase.prototype.hasContent = mustBeOverrided; | ||
/** | ||
* Render content | ||
* @return {string} | ||
*/ | ||
InhabitModuleBase.prototype.display = mustBeOverrided; | ||
/** | ||
* ? | ||
*/ | ||
InhabitModuleBase.prototype.destroy = mustBeOverrided; | ||
/** | ||
* Store dependencies | ||
@@ -67,8 +67,8 @@ * @param dependencies | ||
InhabitModuleBase.prototype.inject = function (dependencies) { | ||
this.$ = dependencies.$; | ||
this.handlebars = dependencies.handlebars; | ||
this.textClassificationService = dependencies.textClassificationService; | ||
this.searchEngineService = dependencies.searchEngineService; | ||
this.$ = dependencies.$; | ||
this.handlebars = dependencies.handlebars; | ||
this.textClassificationService = dependencies.textClassificationService; | ||
this.searchEngineService = dependencies.searchEngineService; | ||
return this; | ||
return this; | ||
}; | ||
@@ -81,33 +81,20 @@ | ||
InhabitModuleBase.prototype.configure = function (configuration) { | ||
this.configuration = configuration; | ||
this.configuration = configuration; | ||
return this; | ||
return this; | ||
}; | ||
/** | ||
* Resolve data | ||
* | ||
* @param data | ||
*/ | ||
InhabitModuleBase.prototype.resolve = function (data) { | ||
data.next = function () { | ||
for (var i = 0; i < data.length; i++) { | ||
if (usedContent.indexOf(data[i].id) === -1) { | ||
usedContent.push(data[i].id); | ||
return data[i]; | ||
} | ||
} | ||
}; | ||
this.deferred.resolve(data); | ||
}; | ||
/** | ||
* Static method for publishing Modules | ||
* @param module | ||
* @static | ||
* @param {InhabitModuleBase} | ||
*/ | ||
InhabitModuleBase.publish = function (module) { | ||
MODULE_STORAGE.push(module); | ||
InhabitModuleBase.publish = function (Module) { | ||
MODULE_STORAGE.push(Module); | ||
}; | ||
function mustBeOverrided() { | ||
throw Error('This method must be overrided.'); | ||
} | ||
module.exports = InhabitModuleBase; |
{ | ||
"name": "inhabit-module-base", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A Base Module class for InHabit.", | ||
@@ -5,0 +5,0 @@ "main": "build/InhabitModuleBase.js", |
@@ -7,35 +7,5 @@ "use strict"; | ||
/** | ||
* setImmediate polyfill | ||
*/ | ||
(function (global) { | ||
if (!global.setImmediate) global.setImmediate = (function() { | ||
var head = { }, tail = head; | ||
var ID = Math.random(); | ||
function onmessage(e) { | ||
if(e.data != ID) return; | ||
head = head.next; | ||
var func = head.func; | ||
delete head.func; | ||
func(); | ||
} | ||
if(global.addEventListener) { // IE9+ | ||
global.addEventListener('message', onmessage); | ||
} else { // IE8 | ||
global.attachEvent('onmessage', onmessage ); | ||
} | ||
return function(func) { | ||
tail = tail.next = { func: func }; | ||
global.postMessage(ID, "*"); | ||
}; | ||
}()); | ||
})(global || window); | ||
/** | ||
* | ||
* @constructor | ||
* @param configuration | ||
* @param dependencies | ||
* @constructor | ||
*/ | ||
@@ -56,6 +26,39 @@ function InhabitModuleBase(configuration, dependencies) { | ||
this.deferred = this.$.Deferred(); | ||
this.content = []; | ||
} | ||
/** | ||
* Start async task that fetches content and return a this.deffered.promise() | ||
* @returns {Promise} | ||
*/ | ||
InhabitModuleBase.prototype.getContent = mustBeOverrided; | ||
/** | ||
* Return a Thumbnail URL | ||
* @returns {string} | ||
*/ | ||
InhabitModuleBase.prototype.getThumbnail = mustBeOverrided; | ||
/** | ||
* Return a Title | ||
* @returns {string} | ||
*/ | ||
InhabitModuleBase.prototype.getTitle = mustBeOverrided; | ||
/** | ||
* @returns {boolean} | ||
*/ | ||
InhabitModuleBase.prototype.hasContent = mustBeOverrided; | ||
/** | ||
* Render content | ||
* @return {string} | ||
*/ | ||
InhabitModuleBase.prototype.display = mustBeOverrided; | ||
/** | ||
* ? | ||
*/ | ||
InhabitModuleBase.prototype.destroy = mustBeOverrided; | ||
/** | ||
* Store dependencies | ||
@@ -85,27 +88,14 @@ * @param dependencies | ||
/** | ||
* Resolve data | ||
* | ||
* @param data | ||
*/ | ||
InhabitModuleBase.prototype.resolve = function (data) { | ||
data.next = function () { | ||
for (var i = 0; i < data.length; i++) { | ||
if (usedContent.indexOf(data[i].id) === -1) { | ||
usedContent.push(data[i].id); | ||
return data[i]; | ||
} | ||
} | ||
}; | ||
this.deferred.resolve(data); | ||
}; | ||
/** | ||
* Static method for publishing Modules | ||
* @param module | ||
* @static | ||
* @param {InhabitModuleBase} | ||
*/ | ||
InhabitModuleBase.publish = function (module) { | ||
MODULE_STORAGE.push(module); | ||
InhabitModuleBase.publish = function (Module) { | ||
MODULE_STORAGE.push(Module); | ||
}; | ||
function mustBeOverrided() { | ||
throw Error('This method must be overrided.'); | ||
} | ||
module.exports = InhabitModuleBase; |
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
34689
220