From a343db133e26d8d8a2e0f5b25eec7453aee5550c Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Mon, 29 May 2023 12:49:42 +0200 Subject: [PATCH] improved KVStore --- src/lib/KVStore.hx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/KVStore.hx b/src/lib/KVStore.hx index ab210f8..107f3fd 100644 --- a/src/lib/KVStore.hx +++ b/src/lib/KVStore.hx @@ -10,7 +10,7 @@ import haxe.ds.StringMap; **/ class KVStore { private var kvStore: StringMap = new StringMap(); - private final namespace:String; + public final namespace:String; public function new(namespace: String) { this.namespace = namespace; @@ -21,6 +21,11 @@ class KVStore { FS.delete(nsFile); } + public static function getStoreForClass(?pos:haxe.PosInfos) { + var className = pos.className; + return new KVStore(className); + } + private static function getNamespaceFile(namespace: String): String { return '/var/ns/$namespace'; } @@ -50,8 +55,8 @@ class KVStore { this.kvStore.set(key,value); } - public inline function get(key: String): Null { - return this.kvStore.get(key); + public inline function get(key: String,?orElse:T = null): Null { + return this.kvStore.get(key) ?? orElse; } public inline function exists(key: String): Bool {