Skip to content

Commit

Permalink
Fix loop keep overiding the kv by not loading the kv directly and ins…
Browse files Browse the repository at this point in the history
…tead to a varible
  • Loading branch information
mickeydarrenlau committed Feb 9, 2024
1 parent 7a513d4 commit 1192884
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
30 changes: 15 additions & 15 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,39 @@ declare global {
}

class SharedStuff {
#stuff: {[key: string]: any};
#this2: any;
constructor(private stuff: {[key: string]: any;}, private this2: any) {
this.#stuff = stuff;
this.#this2 = this2;
this.stuff = stuff;
this.this2 = this2;
}

set(name: string, value: any) {
this.#stuff[name] = value;
this.#this2.saveSettings();
this.stuff[name] = value;
this.this2.saveSettings();
}

get(name: string) {
return this.#stuff[name];
return this.stuff[name];
}

delete(name: string) {
delete this.#stuff[name];
this.#this2.saveSettings();
delete this.stuff[name];
this.this2.saveSettings();
}

has(name: string) {
return this.#stuff.hasOwnProperty(name);
return this.stuff.hasOwnProperty(name);
}

keys() {
return Object.keys(this.#stuff);
return Object.keys(this.stuff);
}

values() {
return Object.values(this.#stuff);
return Object.values(this.stuff);
}

entries() {
return Object.entries(this.#stuff);
return Object.entries(this.stuff);
}
}

Expand All @@ -78,16 +76,18 @@ export default class ObisidianKV extends Plugin {

let updateinterval = setInterval(async () => {
let currentdata = this.settings.kvdata
await this.loadSettings();
if(JSON.stringify(this.settings.kvdata) == JSON.stringify(currentdata)) {
let newkvdata = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
if(JSON.stringify(newkvdata.kvdata) == JSON.stringify(currentdata)) {
return;
} else {
await this.loadSettings();
window.kv = new SharedStuff(this.settings.kvdata, this2);
console.log("[ " + this.manifest.id +" ] Updated kv data");
}
}, 1000);

this.privatekv.set("updateinterval", updateinterval);
//clearInterval(this.privatekv.get("updateinterval"));



Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "kv-store",
"name": "KV Store",
"version": "1.0.3",
"version": "1.0.4",
"minAppVersion": "0.15.0",
"description": "Adds a key-value store to Obsidian. Use it to store and retrieve key-value pairs in your vault.",
"author": "Darren-project",
Expand Down
2 changes: 1 addition & 1 deletion version-bump.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync, writeFileSync } from "fs";

const targetVersion = "1.0.3";
const targetVersion = "1.0.4";

// read minAppVersion from manifest.json and bump version to target version
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"1.0.0": "0.15.0",
"1.0.2": "0.15.0",
"1.0.3": "0.15.0"
"1.0.3": "0.15.0",
"1.0.4": "0.15.0"
}

0 comments on commit 1192884

Please sign in to comment.