trilium/src/public/app/entities/branch.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-08-23 18:55:45 +08:00
/** Represents mapping between note and parent note */
class Branch {
constructor(treeCache, row) {
this.treeCache = treeCache;
2020-01-30 05:32:22 +08:00
this.update(row);
}
update(row) {
2018-08-23 18:55:45 +08:00
/** @param {string} primary key */
this.branchId = row.branchId;
2018-08-23 18:55:45 +08:00
/** @param {string} */
this.noteId = row.noteId;
2018-08-23 18:55:45 +08:00
/** @param {string} */
this.parentNoteId = row.parentNoteId;
2018-08-23 18:55:45 +08:00
/** @param {int} */
this.notePosition = row.notePosition;
2018-08-23 18:55:45 +08:00
/** @param {string} */
this.prefix = row.prefix;
2018-08-23 18:55:45 +08:00
/** @param {boolean} */
2018-11-26 21:47:46 +08:00
this.isExpanded = !!row.isExpanded;
2020-02-11 03:57:56 +08:00
/** @param {boolean} */
this.isDeleted = !!row.isDeleted;
}
2018-08-23 18:55:45 +08:00
/** @returns {NoteShort} */
async getNote() {
return this.treeCache.getNote(this.noteId);
}
2020-01-12 16:57:28 +08:00
/** @returns {NoteShort} */
async getParentNote() {
return this.treeCache.getNote(this.parentNoteId);
}
2018-08-23 18:55:45 +08:00
/** @returns {boolean} true if it's top level, meaning its parent is root note */
isTopLevel() {
return this.parentNoteId === 'root';
}
get toString() {
return `Branch(branchId=${this.branchId})`;
}
}
export default Branch;