summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Van Doorn <vandoorn.nick@gmail.com>2019-03-02 16:29:34 -0800
committerNick Van Doorn <vandoorn.nick@gmail.com>2019-03-02 16:29:34 -0800
commitd5d5b6bd67169eeb915a31b3ceb3e06e0032e1e9 (patch)
tree0c6918565b082c0ea60b7f7742afc19473d5fb53
parent16de86a07d156dcd675047198be6273f7dbeadfa (diff)
Merge objects before writing
-rw-r--r--core/src/database.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/src/database.ts b/core/src/database.ts
index 6221fc2..6bd7c46 100644
--- a/core/src/database.ts
+++ b/core/src/database.ts
@@ -83,16 +83,21 @@ export class Database implements DatabaseInterface {
}
async write(path: string, toWrite: any): Promise<void> {
+ let toSet
if (isRootNode(path)) {
this.buff = toWrite
+ toSet = toWrite
} else {
const pathParts = splitPath(path)
+ const key = last(pathParts)
const writeTo = this.resolve(pathParts, false, 1)
- writeTo[last(pathParts)] = toWrite
+ const prev = writeTo[key]
+ toSet = { ...prev, ...toWrite }
+ writeTo[key] = toSet
}
await this.serialize()
// alert everyone of our new change
- await this.runChangeHandlers(path, toWrite)
+ await this.runChangeHandlers(path, toSet)
}
private async runChangeHandlers(path: string, change: any): Promise<void> {