1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-18 23:07:45 +02:00

All: Moving sync target logic to SyncTarget classes

This commit is contained in:
Laurent Cozic
2017-11-24 18:59:16 +00:00
parent cc7cbc2ecf
commit 112609c5f1
17 changed files with 78 additions and 61 deletions

View File

@ -1,16 +1,21 @@
const syncTargetClasses_ = {
1: require('lib/SyncTarget1.js'),
2: require('lib/SyncTarget2.js'),
3: require('lib/SyncTarget3.js'),
};
class SyncTargetRegistry {
static classById(syncTargetId) {
if (!syncTargetClasses_[syncTargetId]) throw new Error('Invalid id: ' + syncTargetId);
return syncTargetClasses_[syncTargetId];
const info = SyncTargetRegistry.reg_[syncTargetId];
if (!info) throw new Error('Invalid id: ' + syncTargetId);
return info.classRef;
}
static addClass(SyncTargetClass) {
this.reg_[SyncTargetClass.id()] = {
id: SyncTargetClass.id(),
label: SyncTargetClass.label(),
classRef: SyncTargetClass,
};
}
}
SyncTargetRegistry.reg_ = {};
module.exports = SyncTargetRegistry;