Skip to content

Commit 09f9557

Browse files
author
Snowflake107
committed
dev#push
1 parent 53c6164 commit 09f9557

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Database.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,16 @@ class Database {
299299
}
300300

301301
push(key, valueLike, options = {}) {
302+
const has = this.has(key, options);
303+
if (!has) return this.set(key, !Array.isArray(valueLike) ? [valueLike] : valueLike, options);
304+
302305
const data = this.get(key, options);
303-
if (!data) return this.set(key, !Array.isArray(valueLike) ? [valueLike] : valueLike, options);
304306
if (!Array.isArray(data)) throw new TypeError("Cannot use push with non-array type");
305307
if (Array.isArray(valueLike)) {
306308
const n = data.concat(valueLike);
307309
return this.set(key, n, options);
308310
}
309-
const res = [];
311+
const res = [...data];
310312
res.push(valueLike);
311313
return this.set(key, res, options);
312314
}

0 commit comments

Comments
 (0)