},
};
-const Log = {
- addTask: function (description: string) {
- this.applyLogEntry(`${Date.now()} Create ${description}`);
- },
+const Log = (function () {
+ var next_log_index = 0;
+ return {
+ addTask: function (description: string) {
+ this.recordAndApplyLogEntry(`${Date.now()} Create ${description}`);
+ },
- applyLogEntry: function (entry: string) {
- const [timestamp, command, data] = splitN(entry, " ", 2);
- if (command == "Create") {
- Model.addTask(data);
- }
- },
-};
+ applyLogEntry: function (entry: string) {
+ const [timestamp, command, data] = splitN(entry, " ", 2);
+ if (command == "Create") {
+ Model.addTask(data);
+ }
+ },
+
+ recordLogEntry: function (entry: string) {
+ window.localStorage.setItem(`${next_log_index++}`, entry);
+ },
+
+ recordAndApplyLogEntry: function (entry: string) {
+ this.recordLogEntry(entry);
+ this.applyLogEntry(entry);
+ },
+
+ replay: function () {
+ while (true) {
+ const entry = window.localStorage.getItem(`${next_log_index}`);
+ if (entry === null) {
+ break;
+ }
+ this.applyLogEntry(entry);
+ next_log_index++;
+ }
+ },
+ };
+})();
function handleKey(event: any) {
if (event.target.tagName !== "INPUT") {
function browserInit() {
document.body.addEventListener("keydown", handleKey, { capture: false });
+ Log.replay();
}