0
1
Fork 0
hedera-web-mindshore/js/hedera/module.js

71 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-06-06 16:19:43 +00:00
module.exports = new Class({
2022-11-28 08:51:31 +00:00
basePath: null,
path: null,
moduleName: null,
resolvers: null,
status: null,
2022-11-28 08:51:31 +00:00
initialize(basePath, path) {
const aux = path.split('/');
const moduleName = aux[aux.length - 1];
this.basePath = basePath;
this.path = path;
this.moduleName = moduleName;
2022-11-28 08:51:31 +00:00
},
2022-11-28 08:51:31 +00:00
async load() {
switch(this.status) {
case 'ready':
return;
case 'loading':
return new Promise((resolve, reject) => {
this.resolvers.push(status => {
if (status == 'error')
return reject(new Error(`Module could not be loaded`));
resolve();
});
});
}
2022-11-28 08:51:31 +00:00
this.status = 'loading';
this.resolvers = [];
const absPath = `${this.basePath}/${this.path}`;
const requests = [
Vn.includeJs(`${absPath}/${this.moduleName}.js`),
Vn.loadXml(`${absPath}/ui.xml`)
];
2015-11-09 08:14:33 +00:00
2022-11-28 08:51:31 +00:00
try {
await Vn.Locale.load(absPath);
} catch(err) {
console.err(err);
}
try {
2022-11-28 08:51:31 +00:00
await Promise.all(requests);
const klassName = this.toCamelCase(this.moduleName);
2016-09-26 09:28:47 +00:00
this.klass = Hedera[klassName];
2022-11-28 08:51:31 +00:00
this.status = 'ready';
} catch (err) {
this.status = 'error';
console.error(err);
}
2022-11-28 08:51:31 +00:00
for (const resolver of this.resolvers)
resolver(this.status);
2022-11-28 08:51:31 +00:00
this.resolvers = null;
}
2022-11-16 01:46:44 +00:00
,toCamelCase(dashedName) {
2022-06-06 16:19:43 +00:00
var camelCase = dashedName.charAt(0).toUpperCase();
camelCase += dashedName.substr(1).replace(/\w-\w/g, function(token) {
return token.charAt(0) + token.charAt(2).toUpperCase();
});
return camelCase;
}
});