From 21449685f1bd92329cc925909b464870a6398dd3 Mon Sep 17 00:00:00 2001 From: Geoff Doty Date: Sat, 7 Apr 2018 00:18:48 -0400 Subject: [PATCH] fixed array of objects support for add() --- src/record.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/record.js b/src/record.js index e20742a..6da86e0 100644 --- a/src/record.js +++ b/src/record.js @@ -73,27 +73,44 @@ */ add(entry) { + // for array of entries if (Array.isArray(entry)) { + // temp array + let entries = []; + entry.forEach(() => { + // add id if not provided if (!entry.id) { entry.id = Math.random().toString(36).substr(2, 9); } + // add entry to records collection this.records.push(entry); - return entry; + // used to return all added + this.entries.push(entry); }); + // save to storage this._save(); + + // return added entry(s) + return entries; + + // if single entry } else { + // add id if not provided if (!entry.id) { entry.id = Math.random().toString(36).substr(2, 9); } + // add entry to records collection this.records.push(entry); // save to storage this._save(); + + // return added entry return entry; } }