From 6670a6de6c0ca769539f1a18afd15da3fe3188c6 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sun, 28 Feb 2021 01:33:25 -0600 Subject: [PATCH] offline support --- nullboard.html | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/nullboard.html b/nullboard.html index cea4746..55008ee 100644 --- a/nullboard.html +++ b/nullboard.html @@ -1398,7 +1398,7 @@ try { this.deltas.popEach((key) => { - console.log("syncing to replicas: " + key); + console.log("syncing: " + key); this.replicate(key); }); } @@ -1429,14 +1429,20 @@ replicate(key) { var value = this.cache().get(key); + this.replicateOne(this.primary(), key, value); this.replicas().forEach((database) => { - if (value) - database.set(key, value); - else - database.del(key, value); + this.replicateOne(database, key, value); }); } + replicateOne(database, key, value) + { + if (value) + database.set(key, value); + else + database.del(key); + } + get(key) { return this.cache().get(key); @@ -1444,11 +1450,12 @@ set(key, value) { - this.primary().set(key, value); this.deltas.push(key); try { - this.replicas().forEach((database) => { + this.cache().set(key, value); + this.primary().set(key, value); + this.replicas().slice(1).forEach((database) => { database.set(key, value); }); this.deltas.pop(key); @@ -1461,11 +1468,12 @@ del(key) { - this.primary().del(key); this.deltas.push(key); try { - this.replicas().forEach((database) => { + this.cache().del(key); + this.primary().del(key); + this.replicas().slice(1).forEach((database) => { database.del(key); }); this.deltas.pop(key);