extract to method duplicated code
This commit is contained in:
parent
d1a207941d
commit
b29e865cd6
|
@ -203,51 +203,37 @@ class CodeGenerator {
|
|||
}
|
||||
|
||||
generateStorageInitialization(useEmbarkJS) {
|
||||
let self = this;
|
||||
if (!useEmbarkJS || this.storageConfig === {}) return "";
|
||||
|
||||
let result = "\n";
|
||||
|
||||
if (!useEmbarkJS || self.storageConfig === {}) return "";
|
||||
|
||||
result += Templates.define_when_env_loaded();
|
||||
|
||||
let pluginsWithCode = this.plugins.getPluginsFor('initCode');
|
||||
if (pluginsWithCode.length > 0) {
|
||||
for (let plugin of pluginsWithCode) {
|
||||
let initCodes = plugin.embarkjs_init_code.storage || [];
|
||||
for (let initCode of initCodes) {
|
||||
let [block, shouldInit] = initCode;
|
||||
if (shouldInit.call(plugin, self.storageConfig)) {
|
||||
result += Templates.exec_when_env_loaded({block: block});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result += this._getInitCode('storage', this.storageConfig);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
generateCommunicationInitialization(useEmbarkJS) {
|
||||
let self = this;
|
||||
if (!useEmbarkJS || this.communicationConfig === {}) return "";
|
||||
|
||||
let result = "\n";
|
||||
|
||||
if (!useEmbarkJS || self.communicationConfig === {}) return "";
|
||||
|
||||
// TODO: don't repeat this twice; should have 'requirements' generator first
|
||||
result += Templates.define_when_env_loaded();
|
||||
result += this._getInitCode('communication', this.communicationConfig);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
_getInitCode(codeType, config) {
|
||||
let result = "";
|
||||
let pluginsWithCode = this.plugins.getPluginsFor('initCode');
|
||||
if (pluginsWithCode.length > 0) {
|
||||
for (let plugin of pluginsWithCode) {
|
||||
let initCodes = plugin.embarkjs_init_code.communication || [];
|
||||
let initCodes = plugin.embarkjs_init_code[codeType] || [];
|
||||
for (let initCode of initCodes) {
|
||||
let [block, shouldInit] = initCode;
|
||||
if (shouldInit.call(plugin, self.communicationConfig)) {
|
||||
if (shouldInit.call(plugin, config)) {
|
||||
result += Templates.exec_when_env_loaded({block: block});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue