69 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-05-17 09:48:24 +02:00
"use strict";
2020-08-27 23:54:02 +02:00
const Note = require('./note.js');
2020-05-17 09:48:24 +02:00
class Branch {
2021-04-16 23:00:08 +02:00
constructor(becca, row) {
/** @param {Becca} */
this.becca = becca;
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;
2020-12-11 22:06:12 +01:00
/** @param {int} */
this.notePosition = row.notePosition;
/** @param {boolean} */
this.isExpanded = !!row.isExpanded;
2020-05-16 23:12:29 +02:00
if (this.branchId === 'root') {
return;
}
const childNote = this.childNote;
2020-05-16 23:12:29 +02:00
const parentNote = this.parentNote;
childNote.parents.push(parentNote);
childNote.parentBranches.push(this);
parentNote.children.push(childNote);
2021-04-16 23:00:08 +02:00
this.becca.branches[this.branchId] = this;
this.becca.childParentToBranch[`${this.noteId}-${this.parentNoteId}`] = this;
2020-05-16 23:12:29 +02:00
}
/** @return {Note} */
get childNote() {
2021-04-16 23:00:08 +02:00
if (!(this.noteId in this.becca.notes)) {
// entities can come out of order in sync, create skeleton which will be filled later
2021-04-16 23:00:08 +02:00
this.becca.notes[this.noteId] = new Note(this.becca, {noteId: this.noteId});
}
2021-04-16 23:00:08 +02:00
return this.becca.notes[this.noteId];
}
2020-05-16 23:12:29 +02:00
/** @return {Note} */
get parentNote() {
2021-04-16 23:00:08 +02:00
if (!(this.parentNoteId in this.becca.notes)) {
// entities can come out of order in sync, create skeleton which will be filled later
2021-04-16 23:00:08 +02:00
this.becca.notes[this.parentNoteId] = new Note(this.becca, {noteId: this.parentNoteId});
2020-05-16 23:12:29 +02:00
}
2021-04-16 23:00:08 +02:00
return this.becca.notes[this.parentNoteId];
2020-05-16 23:12:29 +02:00
}
// for logging etc
get pojo() {
const pojo = {...this};
2021-04-16 23:00:08 +02:00
delete pojo.becca;
return pojo;
}
2020-05-16 23:12:29 +02:00
}
2020-05-17 09:48:24 +02:00
module.exports = Branch;