From: Scott Worley Date: Wed, 26 Jan 2022 17:45:41 +0000 (-0800) Subject: Use a prefix for localStorage keys X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/d03daa19edde54d43693dca896f6fabade18d326?ds=inline;hp=01f418592aab444588d6d64d53aecf70644e45c0 Use a prefix for localStorage keys --- diff --git a/vopamoi.ts b/vopamoi.ts index 2b38dd8..59c2875 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -53,7 +53,7 @@ const Model = { }, }; -const Log = (function () { +function Log(prefix: string = "vp-") { var next_log_index = 0; return { apply: function (entry: string) { @@ -71,7 +71,7 @@ const Log = (function () { }, record: function (entry: string) { - window.localStorage.setItem(`${next_log_index++}`, entry); + window.localStorage.setItem(`${prefix}${next_log_index++}`, entry); }, recordAndApply: function (entry: string) { @@ -81,7 +81,7 @@ const Log = (function () { replay: function () { while (true) { - const entry = window.localStorage.getItem(`${next_log_index}`); + const entry = window.localStorage.getItem(`${prefix}${next_log_index}`); if (entry === null) { break; } @@ -90,17 +90,18 @@ const Log = (function () { } }, }; -})(); +} +const log = Log(); const UI = { addTask: function (description: string) { - Log.recordAndApply(`${Date.now()} Create ${description}`); + log.recordAndApply(`${Date.now()} Create ${description}`); }, destroyTask: function (createTimestamp: string) { - Log.recordAndApply(`${Date.now()} Destroy ${createTimestamp} ${Model.getTask(createTimestamp)?.textContent}`); + log.recordAndApply(`${Date.now()} Destroy ${createTimestamp} ${Model.getTask(createTimestamp)?.textContent}`); }, setState: function (createTimestamp: string, state: string) { - Log.recordAndApply(`${Date.now()} State ${createTimestamp} ${state}`); + log.recordAndApply(`${Date.now()} State ${createTimestamp} ${state}`); }, }; @@ -161,5 +162,5 @@ function handleKey(event: any) { function browserInit() { document.body.addEventListener("keydown", handleKey, { capture: false }); - Log.replay(); + log.replay(); }