Skip to content

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

fix: don't mutate the notebook object

thecodrr4a96a0aae2a3
diff --git a/packages/core/__tests__/notebooks.test.js b/packages/core/__tests__/notebooks.test.js
index 1d64cc7de..27d1edaad 100644
--- a/packages/core/__tests__/notebooks.test.js
+++ b/packages/core/__tests__/notebooks.test.js
@@ -36,6 +36,7 @@ test("pin a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.pin();
+ notebook = db.notebooks.notebook(id);
expect(notebook.data.pinned).toBe(true);
}));
@@ -43,8 +44,10 @@ test("unpin a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.pin();
+ notebook = db.notebooks.notebook(id);
expect(notebook.data.pinned).toBe(true);
await notebook.pin();
+ notebook = db.notebooks.notebook(id);
expect(notebook.data.pinned).toBe(false);
}));
@@ -52,6 +55,7 @@ test("favorite a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.favorite();
+ notebook = db.notebooks.notebook(id);
expect(notebook.data.favorite).toBe(true);
}));
@@ -59,8 +63,10 @@ test("unfavorite a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.favorite();
+ notebook = db.notebooks.notebook(id);
expect(notebook.data.favorite).toBe(true);
await notebook.favorite();
+ notebook = db.notebooks.notebook(id);
expect(notebook.data.favorite).toBe(false);
}));
diff --git a/packages/core/models/notebook.js b/packages/core/models/notebook.js
index 87310fe0c..071bb2289 100644
--- a/packages/core/models/notebook.js
+++ b/packages/core/models/notebook.js
@@ -25,8 +25,10 @@ export default class Notebook {
}
toggle(prop) {
- this.notebook[prop] = !this.notebook[prop];
- return this.notebooks.add(this.notebook);
+ return this.notebooks.add({
+ id: this.notebook.id,
+ [prop]: !this.notebook[prop]
+ });
}
pin() {