1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00
joplin/ReactNativeClient/lib/SyncTargetRegistry.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

class SyncTargetRegistry {
static classById(syncTargetId) {
const info = SyncTargetRegistry.reg_[syncTargetId];
2019-09-19 23:51:18 +02:00
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,
supportsConfigCheck: SyncTargetClass.supportsConfigCheck(),
};
}
static nameToId(name) {
for (const n in this.reg_) {
if (!this.reg_.hasOwnProperty(n)) continue;
if (this.reg_[n].name === name) return this.reg_[n].id;
}
2019-09-19 23:51:18 +02:00
throw new Error(`Name not found: ${name}`);
}
static idToMetadata(id) {
for (const n in this.reg_) {
if (!this.reg_.hasOwnProperty(n)) continue;
if (this.reg_[n].id === id) return this.reg_[n];
}
2019-09-19 23:51:18 +02:00
throw new Error(`ID not found: ${id}`);
}
static idToName(id) {
return this.idToMetadata(id).name;
}
static idAndLabelPlainObject(os) {
const output = {};
for (const n in this.reg_) {
if (!this.reg_.hasOwnProperty(n)) continue;
const info = this.reg_[n];
if (info.classRef.unsupportedPlatforms().indexOf(os) >= 0) {
continue;
}
output[n] = info.label;
}
return output;
}
}
SyncTargetRegistry.reg_ = {};
2019-07-29 15:43:53 +02:00
module.exports = SyncTargetRegistry;