commit f8d36e92086135f9e3e5da7163b20e7ed9690038
parent 815504354ba6a10877f0099e6ac973bd5b516154
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 19 Aug 2024 10:02:51 -0700
Separate patching from pull into it's own method
This will allow for future use in other applications.
Diffstat:
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/files/floorplans/floorplan/backend.js b/files/floorplans/floorplan/backend.js
@@ -345,20 +345,23 @@ export class FloorplanBackend {
.then(function(data) {
let diff = gendiff("", backend.cache, data)
console.log("Backend.Pull (diff)", diff)
- backend.newDiff()
- let options = { clean: true }
- for (let i in diff) {
- let ref = parsePath(diff[i].path)
- if (diff[i].op === "remove") {
- backend.removeData(ref.type, ref.id, options)
- } else {
- backend.addData(ref.type, diff[i].value, ref.id, options)
- }
- }
- backend.newDiff()
+ backend.applyDiff(diff, { clean: true })
backend.cb("pull")
})
}
+
+ applyDiff(diff, options) {
+ this.newDiff()
+ for (let i in diff) {
+ let ref = parsePath(diff[i].path)
+ if (diff[i].op === "remove") {
+ this.removeData(ref.type, ref.id, options)
+ } else {
+ this.addData(ref.type, diff[i].value, ref.id, options)
+ }
+ }
+ this.newDiff()
+ }
}
function gendiff(path, a, b) {