Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

perf: return notebook instead of notebook id

thecodrr4283a5ba341d
diff --git a/packages/core/__tests__/notes.test.js b/packages/core/__tests__/notes.test.js
index 709f91101..0918b814e 100644
--- a/packages/core/__tests__/notes.test.js
+++ b/packages/core/__tests__/notes.test.js
@@ -251,7 +251,7 @@ test("lock and unlock note", () =>
test("add note to topic", () =>
noteTest().then(async ({ db, id }) => {
- let notebookId = await db.notebooks.add({ title: "Hello" });
+ let { id: notebookId } = await db.notebooks.add({ title: "Hello" });
let topics = db.notebooks.notebook(notebookId).topics;
await topics.add("Home");
let topic = topics.topic("Home");
@@ -292,7 +292,7 @@ test("move note", () =>
test("moving note to same notebook and topic should do nothing", () =>
noteTest().then(async ({ db, id }) => {
- let notebookId = await db.notebooks.add({ title: "Hello" });
+ const { id: notebookId } = await db.notebooks.add({ title: "Hello" });
let topics = db.notebooks.notebook(notebookId).topics;
await topics.add("Home");
let topic = topics.topic("Home");
diff --git a/packages/core/__tests__/trash.test.js b/packages/core/__tests__/trash.test.js
index a6db7b6f7..792758a6c 100644
--- a/packages/core/__tests__/trash.test.js
+++ b/packages/core/__tests__/trash.test.js
@@ -25,7 +25,7 @@ test("delete a note", () =>
test("restore a deleted note", () =>
noteTest().then(async ({ db, id }) => {
- let nbId = await db.notebooks.add(TEST_NOTEBOOK);
+ let { id: nbId } = await db.notebooks.add(TEST_NOTEBOOK);
await db.notebooks
.notebook(nbId)
.topics.topic("General")
@@ -47,7 +47,7 @@ test("restore a deleted note", () =>
test("restore a deleted note that's in a deleted notebook", () =>
noteTest().then(async ({ db, id }) => {
- let nbId = await db.notebooks.add(TEST_NOTEBOOK);
+ let { id: nbId } = await db.notebooks.add(TEST_NOTEBOOK);
await db.notebooks
.notebook(nbId)
.topics.topic("General")
diff --git a/packages/core/__tests__/utils/index.js b/packages/core/__tests__/utils/index.js
index 20cb92207..41c6ca675 100644
--- a/packages/core/__tests__/utils/index.js
+++ b/packages/core/__tests__/utils/index.js
@@ -21,8 +21,8 @@ function databaseTest() {
const notebookTest = (notebook = TEST_NOTEBOOK) =>
databaseTest().then(async db => {
- let id = await db.notebooks.add(notebook);
- return { db, id };
+ let nb = await db.notebooks.add(notebook);
+ return { db, id: nb ? nb.id : undefined };
});
var TEST_NOTE = {
diff --git a/packages/core/collections/notebooks.js b/packages/core/collections/notebooks.js
index 41ef54d32..bc9f71bc7 100644
--- a/packages/core/collections/notebooks.js
+++ b/packages/core/collections/notebooks.js
@@ -54,10 +54,10 @@ export default class Notebooks {
await this._collection.addItem(notebook);
- //if (!oldNotebook) {
- await this.notebook(notebook.id).topics.add(...notebook.topics);
- //}
- return notebook.id;
+ if (!oldNotebook) {
+ await this.notebook(notebook).topics.add(...notebook.topics);
+ }
+ return notebook;
}
get all() {
@@ -70,7 +70,7 @@ export default class Notebooks {
* @returns {Notebook} The notebook of the given id
*/
notebook(id) {
- let notebook = this._collection.getItem(id);
+ let notebook = id.type ? id : this._collection.getItem(id);
if (!notebook) return;
return new Notebook(this, notebook);
}