From 45fa64765555e773ef043755bcc62905b9d4981c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 6 Oct 2020 13:55:39 +0100 Subject: [PATCH] Convert SendHistoryManager to TS Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/{SendHistoryManager.js => SendHistoryManager.ts} | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) rename src/{SendHistoryManager.js => SendHistoryManager.ts} (84%) diff --git a/src/SendHistoryManager.js b/src/SendHistoryManager.ts similarity index 84% rename from src/SendHistoryManager.js rename to src/SendHistoryManager.ts index d9955727a4..106fcb51fb 100644 --- a/src/SendHistoryManager.js +++ b/src/SendHistoryManager.ts @@ -16,12 +16,14 @@ limitations under the License. */ import {clamp} from "lodash"; +import {SerializedPart} from "./editor/parts"; +import EditorModel from "./editor/model"; export default class SendHistoryManager { - history: Array = []; + history: Array = []; prefix: string; - lastIndex: number = 0; // used for indexing the storage - currentIndex: number = 0; // used for indexing the loaded validated history Array + lastIndex = 0; // used for indexing the storage + currentIndex = 0; // used for indexing the loaded validated history Array constructor(roomId: string, prefix: string) { this.prefix = prefix + roomId; @@ -45,7 +47,7 @@ export default class SendHistoryManager { this.currentIndex = this.lastIndex + 1; } - save(editorModel: Object) { + save(editorModel: EditorModel) { const serializedParts = editorModel.serializeParts(); this.history.push(serializedParts); this.currentIndex = this.history.length; @@ -53,7 +55,7 @@ export default class SendHistoryManager { sessionStorage.setItem(`${this.prefix}[${this.lastIndex}]`, JSON.stringify(serializedParts)); } - getItem(offset: number): ?HistoryItem { + getItem(offset: number): SerializedPart[] { this.currentIndex = clamp(this.currentIndex + offset, 0, this.history.length - 1); return this.history[this.currentIndex]; }