mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-03 08:35:29 +02:00
39 lines
894 B
JavaScript
39 lines
894 B
JavaScript
class SyncTargetRegistry {
|
|
|
|
static classById(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(),
|
|
name: SyncTargetClass.targetName(),
|
|
label: SyncTargetClass.label(),
|
|
classRef: SyncTargetClass,
|
|
};
|
|
}
|
|
|
|
static nameToId(name) {
|
|
for (let n in this.reg_) {
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
|
if (this.reg_[n].name === name) return this.reg_[n].id;
|
|
}
|
|
throw new Error('Name not found: ' + name);
|
|
}
|
|
|
|
static idAndLabelPlainObject() {
|
|
let output = {};
|
|
for (let n in this.reg_) {
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
|
output[n] = this.reg_[n].label;
|
|
}
|
|
return output;
|
|
}
|
|
|
|
}
|
|
|
|
SyncTargetRegistry.reg_ = {};
|
|
|
|
module.exports = SyncTargetRegistry; |