From 85c8415acdb76fcf461e9834828255b18e65a23b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 18 Aug 2021 18:21:43 +0200 Subject: [PATCH] convert Direction to ts --- .../timeline/{Direction.js => Direction.ts} | 21 +++++++------------ src/matrix/room/timeline/Timeline.js | 2 +- .../timeline/entries/FragmentBoundaryEntry.js | 2 +- .../timeline/persistence/TimelineReader.js | 2 +- 4 files changed, 11 insertions(+), 16 deletions(-) rename src/matrix/room/timeline/{Direction.js => Direction.ts} (70%) diff --git a/src/matrix/room/timeline/Direction.js b/src/matrix/room/timeline/Direction.ts similarity index 70% rename from src/matrix/room/timeline/Direction.js rename to src/matrix/room/timeline/Direction.ts index c83ec61c..24a8ff41 100644 --- a/src/matrix/room/timeline/Direction.js +++ b/src/matrix/room/timeline/Direction.ts @@ -15,34 +15,29 @@ limitations under the License. */ export class Direction { - constructor(isForward) { - this._isForward = isForward; + constructor(public readonly isForward: boolean) { } - get isForward() { - return this._isForward; - } - - get isBackward() { + get isBackward(): boolean { return !this.isForward; } - asApiString() { + asApiString(): string { return this.isForward ? "f" : "b"; } - reverse() { + reverse(): Direction { return this.isForward ? Direction.Backward : Direction.Forward } - static get Forward() { + static get Forward(): Direction { return _forward; } - static get Backward() { + static get Backward(): Direction { return _backward; } } -const _forward = Object.freeze(new Direction(true)); -const _backward = Object.freeze(new Direction(false)); +const _forward = new Direction(true); +const _backward = new Direction(false); diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index fdfaee48..022eda4e 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -17,7 +17,7 @@ limitations under the License. import {SortedArray, AsyncMappedList, ConcatList, ObservableArray} from "../../../observable/index.js"; import {Disposables} from "../../../utils/Disposables.js"; -import {Direction} from "./Direction.js"; +import {Direction} from "./Direction"; import {TimelineReader} from "./persistence/TimelineReader.js"; import {PendingEventEntry} from "./entries/PendingEventEntry.js"; import {RoomMember} from "../members/RoomMember.js"; diff --git a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js index 0697fbdd..7a8ed5d0 100644 --- a/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js +++ b/src/matrix/room/timeline/entries/FragmentBoundaryEntry.js @@ -15,7 +15,7 @@ limitations under the License. */ import {BaseEntry} from "./BaseEntry"; -import {Direction} from "../Direction.js"; +import {Direction} from "../Direction"; import {isValidFragmentId} from "../common.js"; import {KeyLimits} from "../../../storage/common"; diff --git a/src/matrix/room/timeline/persistence/TimelineReader.js b/src/matrix/room/timeline/persistence/TimelineReader.js index 27b88ea9..ffad80ec 100644 --- a/src/matrix/room/timeline/persistence/TimelineReader.js +++ b/src/matrix/room/timeline/persistence/TimelineReader.js @@ -15,7 +15,7 @@ limitations under the License. */ import {directionalConcat, directionalAppend} from "./common.js"; -import {Direction} from "../Direction.js"; +import {Direction} from "../Direction"; import {EventEntry} from "../entries/EventEntry.js"; import {FragmentBoundaryEntry} from "../entries/FragmentBoundaryEntry.js";