50 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-05-17 09:48:24 +02:00
"use strict";
class Branch {
2020-05-17 10:11:19 +02:00
constructor(noteCache, row) {
/** @param {NoteCache} */
this.noteCache = noteCache;
2020-05-16 23:12:29 +02:00
/** @param {string} */
this.branchId = row.branchId;
/** @param {string} */
this.noteId = row.noteId;
/** @param {string} */
this.parentNoteId = row.parentNoteId;
/** @param {string} */
this.prefix = row.prefix;
if (this.branchId === 'root') {
return;
}
2020-05-17 10:11:19 +02:00
const childNote = this.noteCache.notes[this.noteId];
2020-05-16 23:12:29 +02:00
const parentNote = this.parentNote;
if (!childNote) {
console.log(`Cannot find child note ${this.noteId} of a branch ${this.branchId}`);
return;
}
childNote.parents.push(parentNote);
childNote.parentBranches.push(this);
parentNote.children.push(childNote);
2020-05-22 09:38:30 +02:00
this.noteCache.branches[this.branchId] = this;
2020-05-17 10:11:19 +02:00
this.noteCache.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;
2020-05-16 23:12:29 +02:00
}
/** @return {Note} */
get parentNote() {
2020-05-17 10:11:19 +02:00
const note = this.noteCache.notes[this.parentNoteId];
2020-05-16 23:12:29 +02:00
if (!note) {
console.log(`Cannot find note ${this.parentNoteId}`);
}
return note;
}
}
2020-05-17 09:48:24 +02:00
module.exports = Branch;