]> git.scottworley.com Git - vopamoi/commitdiff
undoLog is private to the UI
authorScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 08:07:27 +0000 (00:07 -0800)
committerScott Worley <scottworley@scottworley.com>
Thu, 27 Jan 2022 20:21:55 +0000 (12:21 -0800)
vopamoi.ts

index 3c592269d8d0bdecaa95ea76d07ae1b40cf65970..a3b782465b64dc32ced3280178e49c069750902a 100644 (file)
@@ -149,32 +149,35 @@ function Log(prefix: string = "vp-") {
 }
 const log = Log();
 
 }
 const log = Log();
 
-const undoLog: string[] = [];
 
 
-const UI = {
-  addTask: function (description: string): Element {
-    const now = clock.now();
-    undoLog.push(`State ${now} deleted`);
-    return <Element>log.recordAndApply(`${now} Create ${description}`);
-  },
-  edit: function (createTimestamp: string, newDescription: string, oldDescription: string) {
-    undoLog.push(`Edit ${createTimestamp} ${oldDescription}`);
-    return log.recordAndApply(`${clock.now()} Edit ${createTimestamp} ${newDescription}`);
-  },
-  setPriority: function (createTimestamp: string, newPriority: number, oldPriority: number) {
-    undoLog.push(`Priority ${createTimestamp} ${oldPriority}`);
-    return log.recordAndApply(`${clock.now()} Priority ${createTimestamp} ${newPriority}`);
-  },
-  setState: function (createTimestamp: string, newState: string, oldState: string) {
-    undoLog.push(`State ${createTimestamp} ${oldState}`);
-    return log.recordAndApply(`${clock.now()} State ${createTimestamp} ${newState}`);
-  },
-  undo: function () {
-    if (undoLog.length > 0) {
-      return log.recordAndApply(`${clock.now()} ${undoLog.pop()}`);
-    }
-  },
-};
+function UI() {
+  const undoLog: string[] = [];
+  return {
+    addTask: function (description: string): Element {
+      const now = clock.now();
+      undoLog.push(`State ${now} deleted`);
+      return <Element>log.recordAndApply(`${now} Create ${description}`);
+    },
+    edit: function (createTimestamp: string, newDescription: string, oldDescription: string) {
+      undoLog.push(`Edit ${createTimestamp} ${oldDescription}`);
+      return log.recordAndApply(`${clock.now()} Edit ${createTimestamp} ${newDescription}`);
+    },
+    setPriority: function (createTimestamp: string, newPriority: number, oldPriority: number) {
+      undoLog.push(`Priority ${createTimestamp} ${oldPriority}`);
+      return log.recordAndApply(`${clock.now()} Priority ${createTimestamp} ${newPriority}`);
+    },
+    setState: function (createTimestamp: string, newState: string, oldState: string) {
+      undoLog.push(`State ${createTimestamp} ${oldState}`);
+      return log.recordAndApply(`${clock.now()} State ${createTimestamp} ${newState}`);
+    },
+    undo: function () {
+      if (undoLog.length > 0) {
+        return log.recordAndApply(`${clock.now()} ${undoLog.pop()}`);
+      }
+    },
+  };
+}
+const ui = UI();
 
 function BrowserUI() {
   var currentViewState = "todo";
 
 function BrowserUI() {
   var currentViewState = "todo";
@@ -182,7 +185,7 @@ function BrowserUI() {
     addTask: function (event: KeyboardEvent) {
       const input = <HTMLInputElement>document.getElementById("taskName");
       if (input.value) {
     addTask: function (event: KeyboardEvent) {
       const input = <HTMLInputElement>document.getElementById("taskName");
       if (input.value) {
-        const task = UI.addTask(input.value);
+        const task = ui.addTask(input.value);
         if (task && task instanceof HTMLElement) task.focus();
         input.value = "";
         if (event.getModifierState("Control")) {
         if (task && task instanceof HTMLElement) task.focus();
         input.value = "";
         if (event.getModifierState("Control")) {
@@ -218,7 +221,7 @@ function BrowserUI() {
       if (newDescription === oldDescription) {
         task.textContent = oldDescription;
       } else {
       if (newDescription === oldDescription) {
         task.textContent = oldDescription;
       } else {
-        UI.edit(task.getAttribute("data-created")!, newDescription, oldDescription);
+        ui.edit(task.getAttribute("data-created")!, newDescription, oldDescription);
       }
     },
 
       }
     },
 
@@ -286,7 +289,7 @@ function BrowserUI() {
       console.assert(aPriority < newPriority && newPriority < bPriority, aPriority, "<", newPriority, "<", bPriority);
       const newPriorityRounded = Math.round(newPriority);
       const okToRound = aPriority < newPriorityRounded && newPriorityRounded < bPriority;
       console.assert(aPriority < newPriority && newPriority < bPriority, aPriority, "<", newPriority, "<", bPriority);
       const newPriorityRounded = Math.round(newPriority);
       const okToRound = aPriority < newPriorityRounded && newPriorityRounded < bPriority;
-      UI.setPriority(task.getAttribute("data-created")!, okToRound ? newPriorityRounded : newPriority, Model.getPriority(task));
+      ui.setPriority(task.getAttribute("data-created")!, okToRound ? newPriorityRounded : newPriority, Model.getPriority(task));
       task instanceof HTMLElement && task.focus();
     },
 
       task instanceof HTMLElement && task.focus();
     },
 
@@ -297,7 +300,7 @@ function BrowserUI() {
       if (newState === oldState) return;
       const createTimestamp = task.getAttribute("data-created")!;
       this.moveCursor(1) || this.moveCursor(-1);
       if (newState === oldState) return;
       const createTimestamp = task.getAttribute("data-created")!;
       this.moveCursor(1) || this.moveCursor(-1);
-      return UI.setState(createTimestamp, newState, oldState);
+      return ui.setState(createTimestamp, newState, oldState);
     },
 
     setView: function (state: string) {
     },
 
     setView: function (state: string) {
@@ -311,7 +314,7 @@ function BrowserUI() {
     },
 
     undo: function () {
     },
 
     undo: function () {
-      const ret = UI.undo();
+      const ret = ui.undo();
       if (ret && ret instanceof HTMLElement) ret.focus();
     },
   };
       if (ret && ret instanceof HTMLElement) ret.focus();
     },
   };