Refactor class loading

Signed-off-by: Marius David Wieschollek's avatarMarius David Wieschollek <passwords.public@mdns.eu>
parent 5665daad
......@@ -43,13 +43,11 @@ export default class BasicClassLoader {
* @return {Object}
*/
getClass(name, ...properties) {
let path = name.split('.');
if(!this._classes.hasOwnProperty(path[0]) || !this._classes[path[0]].hasOwnProperty(path[1])) {
if(!this._classes.hasOwnProperty(name)) {
throw new Error(`The class ${name} does not exist`);
}
let creator = this._classes[path[0]][path[1]];
let creator = this._classes[name];
if(creator instanceof Function) {
if(!creator.prototype || creator.hasOwnProperty('arguments') && creator.hasOwnProperty('caller')) {
return creator(...properties);
......@@ -69,17 +67,7 @@ export default class BasicClassLoader {
* @api
*/
registerClass(name, constructor) {
let path = name.split('.');
if(!this._classes.hasOwnProperty(path[0])) {
this._classes[path[0]] = {};
}
if(!this._classes[path[0]].hasOwnProperty(path[1])) {
this._classes[path[1]] = {};
}
this._classes[path[0]][path[1]] = constructor;
this._classes[name] = constructor;
return this;
}
......
This diff is collapsed.
......@@ -11,9 +11,9 @@ export default class EnhancedClassLoader extends DefaultClassLoader {
*/
_getDefaultClasses() {
let classes = super._getDefaultClasses();
classes.model.password = (d) => { return new EnhancedPassword(d, this.getInstance('api')); };
classes.model.folder = (d) => { return new EnhancedFolder(d, this.getInstance('api')); };
classes.model.tag = (d) => { return new EnhancedTag(d, this.getInstance('api')); };
classes['model.password'] = (d) => { return new EnhancedPassword(d, this.getInstance('client')); };
classes['model.folder'] = (d) => { return new EnhancedFolder(d, this.getInstance('client')); };
classes['model.tag'] = (d) => { return new EnhancedTag(d, this.getInstance('client')); };
return classes;
}
......
......@@ -76,7 +76,7 @@ export default class AbstractConverter {
if(data.cseType === 'CSEv1r1') {
data = await this._api.getCseV1Encryption().decrypt(data, this._type);
} else if(data.cseType !== 'none') {
throw this._api.getClass('exception.encryption', data.id, data.cseType);
throw this._api.getClass('exception.encryption.unsupported', data, 'CSEv1r1');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment