Extract ctor types out

This commit is contained in:
RMidhunSuresh 2021-11-24 13:05:13 +05:30
parent 238b9aafb1
commit a8870f2d24
2 changed files with 15 additions and 2 deletions

View File

@ -27,13 +27,20 @@ type RequestMethod = "POST" | "GET" | "PUT";
const CS_R0_PREFIX = "/_matrix/client/r0"; const CS_R0_PREFIX = "/_matrix/client/r0";
const DEHYDRATION_PREFIX = "/_matrix/client/unstable/org.matrix.msc2697.v2"; const DEHYDRATION_PREFIX = "/_matrix/client/unstable/org.matrix.msc2697.v2";
type Ctor = {
homeserver: string;
accessToken: string;
request: RequestFunction;
reconnector: Reconnector;
};
export class HomeServerApi { export class HomeServerApi {
private readonly _homeserver: string; private readonly _homeserver: string;
private readonly _accessToken: string; private readonly _accessToken: string;
private readonly _requestFn: RequestFunction; private readonly _requestFn: RequestFunction;
private readonly _reconnector: Reconnector; private readonly _reconnector: Reconnector;
constructor({homeserver, accessToken, request, reconnector}: {homeserver: string, accessToken: string, request: RequestFunction, reconnector: Reconnector}) { constructor({homeserver, accessToken, request, reconnector}: Ctor) {
// store these both in a closure somehow so it's harder to get at in case of XSS? // store these both in a closure somehow so it's harder to get at in case of XSS?
// one could change the homeserver as well so the token gets sent there, so both must be protected from read/write // one could change the homeserver as well so the token gets sent there, so both must be protected from read/write
this._homeserver = homeserver; this._homeserver = homeserver;

View File

@ -27,6 +27,12 @@ export enum ConnectionStatus {
"Online" "Online"
}; };
type Ctor = {
retryDelay: ExponentialRetryDelay;
createMeasure: () => TimeMeasure;
onlineStatus: OnlineStatus
};
export class Reconnector { export class Reconnector {
private readonly _retryDelay: ExponentialRetryDelay; private readonly _retryDelay: ExponentialRetryDelay;
private readonly _createTimeMeasure: () => TimeMeasure; private readonly _createTimeMeasure: () => TimeMeasure;
@ -36,7 +42,7 @@ export class Reconnector {
private _versionsResponse?: IVersionResponse; private _versionsResponse?: IVersionResponse;
private _stateSince: TimeMeasure; private _stateSince: TimeMeasure;
constructor({retryDelay, createMeasure, onlineStatus}: {retryDelay: ExponentialRetryDelay, createMeasure: () => TimeMeasure, onlineStatus: OnlineStatus}) { constructor({retryDelay, createMeasure, onlineStatus}: Ctor) {
this._onlineStatus = onlineStatus; this._onlineStatus = onlineStatus;
this._retryDelay = retryDelay; this._retryDelay = retryDelay;
this._createTimeMeasure = createMeasure; this._createTimeMeasure = createMeasure;