mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
Merge pull request #460 from vector-im/bwindels/ts-eventkey-direction
Convert EventKey & Direction to typescript + some ts tidbits
This commit is contained in:
commit
9592d286c2
7
doc/TS-MIGRATION.md
Normal file
7
doc/TS-MIGRATION.md
Normal file
@ -0,0 +1,7 @@
|
||||
# Typescript migration
|
||||
|
||||
## Introduce `abstract` & `override`
|
||||
|
||||
- find all methods and getters that throw or are empty in base classes and turn into abstract method or if all methods are abstract, into an interface.
|
||||
- change child impls to not call super.method and to add override
|
||||
- don't allow implicit override in ts config
|
@ -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);
|
@ -15,20 +15,22 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import {KeyLimits} from "../../storage/common";
|
||||
import {Direction} from "./Direction";
|
||||
|
||||
// key for events in the timelineEvents store
|
||||
export class EventKey {
|
||||
constructor(fragmentId, eventIndex) {
|
||||
this.fragmentId = fragmentId;
|
||||
this.eventIndex = eventIndex;
|
||||
constructor(
|
||||
public fragmentId: number,
|
||||
public eventIndex: number
|
||||
) {
|
||||
}
|
||||
|
||||
nextFragmentKey() {
|
||||
nextFragmentKey(): EventKey {
|
||||
// could take MIN_EVENT_INDEX here if it can't be paged back
|
||||
return new EventKey(this.fragmentId + 1, KeyLimits.middleStorageKey);
|
||||
}
|
||||
|
||||
nextKeyForDirection(direction) {
|
||||
nextKeyForDirection(direction: Direction): EventKey {
|
||||
if (direction.isForward) {
|
||||
return this.nextKey();
|
||||
} else {
|
||||
@ -36,35 +38,35 @@ export class EventKey {
|
||||
}
|
||||
}
|
||||
|
||||
previousKey() {
|
||||
previousKey(): EventKey {
|
||||
return new EventKey(this.fragmentId, this.eventIndex - 1);
|
||||
}
|
||||
|
||||
nextKey() {
|
||||
nextKey(): EventKey {
|
||||
return new EventKey(this.fragmentId, this.eventIndex + 1);
|
||||
}
|
||||
|
||||
static get maxKey() {
|
||||
static get maxKey(): EventKey {
|
||||
return new EventKey(KeyLimits.maxStorageKey, KeyLimits.maxStorageKey);
|
||||
}
|
||||
|
||||
static get minKey() {
|
||||
static get minKey(): EventKey {
|
||||
return new EventKey(KeyLimits.minStorageKey, KeyLimits.minStorageKey);
|
||||
}
|
||||
|
||||
static get defaultLiveKey() {
|
||||
static get defaultLiveKey(): EventKey {
|
||||
return EventKey.defaultFragmentKey(KeyLimits.minStorageKey);
|
||||
}
|
||||
|
||||
static defaultFragmentKey(fragmentId) {
|
||||
static defaultFragmentKey(fragmentId: number): EventKey {
|
||||
return new EventKey(fragmentId, KeyLimits.middleStorageKey);
|
||||
}
|
||||
|
||||
toString() {
|
||||
toString(): string {
|
||||
return `[${this.fragmentId}/${this.eventIndex}]`;
|
||||
}
|
||||
|
||||
equals(other) {
|
||||
equals(other: EventKey): boolean {
|
||||
return this.fragmentId === other?.fragmentId && this.eventIndex === other?.eventIndex;
|
||||
}
|
||||
}
|
@ -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";
|
||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
//entries can be sorted, first by fragment, then by entry index.
|
||||
import {EventKey} from "../EventKey.js";
|
||||
import {EventKey} from "../EventKey";
|
||||
export const PENDING_FRAGMENT_ID = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
interface FragmentIdComparer {
|
||||
|
@ -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";
|
||||
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {EventKey} from "../EventKey.js";
|
||||
import {EventKey} from "../EventKey";
|
||||
import {EventEntry} from "../entries/EventEntry.js";
|
||||
import {createEventEntry, directionalAppend} from "./common.js";
|
||||
import {RoomMember, EVENT_TYPE as MEMBER_EVENT_TYPE} from "../../members/RoomMember.js";
|
||||
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {EventKey} from "../EventKey.js";
|
||||
import {EventKey} from "../EventKey";
|
||||
import {EventEntry} from "../entries/EventEntry.js";
|
||||
import {FragmentBoundaryEntry} from "../entries/FragmentBoundaryEntry.js";
|
||||
import {createEventEntry} from "./common.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";
|
||||
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {EventKey} from "../../../room/timeline/EventKey.js";
|
||||
import {EventKey} from "../../../room/timeline/EventKey";
|
||||
import { StorageError } from "../../common";
|
||||
import { encodeUint32 } from "../utils";
|
||||
import {KeyLimits} from "../../common";
|
||||
|
@ -2,7 +2,7 @@
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": true,
|
||||
"noEmit": true,
|
||||
"target": "es6"
|
||||
"target": "ES2020"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user