From 0453fef2cfb03733a816e312c04463cb19eaebb6 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 1 Jul 2021 11:39:01 +0100 Subject: [PATCH] Added option to force reindexing when deleting from a list --- src/stormdb.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/stormdb.js b/src/stormdb.js index ae205fc..1647a4d 100644 --- a/src/stormdb.js +++ b/src/stormdb.js @@ -20,14 +20,19 @@ class StormDB { return this; } - delete() { + delete(reindexLists = false) { let enclosing = this.state; for (let i = 0; i < this.pointers.length - 1; i++) { enclosing = enclosing[this.pointers[i]]; } let final = this.pointers[this.pointers.length - 1]; - delete enclosing[final]; + + if (Array.isArray(enclosing) && reindexLists) { + enclosing.splice(final, 1); + } else { + delete enclosing[final]; + } } push(value) {