Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 69e36a7

Browse files
committed
Docs & cleanup
1 parent 417a72b commit 69e36a7

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

src/modules/AppModule.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,31 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { ModuleFactory } from "./ModuleFactory";
1817
import { RuntimeModule } from "@matrix-org/react-sdk-module-api/lib/RuntimeModule";
18+
19+
import { ModuleFactory } from "./ModuleFactory";
1920
import { ProxiedModuleApi } from "./ProxiedModuleApi";
2021

22+
/**
23+
* Wraps a module factory into a usable module. Acts as a simple container
24+
* for the constructs needed to operate a module.
25+
*/
2126
export class AppModule {
27+
/**
28+
* The module instance.
29+
*/
2230
public readonly module: RuntimeModule;
31+
32+
/**
33+
* The API instance used by the module.
34+
*/
2335
public readonly api = new ProxiedModuleApi();
2436

37+
/**
38+
* Converts a factory into an AppModule. The factory will be called
39+
* immediately.
40+
* @param factory The module factory.
41+
*/
2542
public constructor(factory: ModuleFactory) {
2643
this.module = factory(this.api);
2744
}

src/modules/ModuleComponents.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// TODO: @@ Is this future-proof enough? Will we remember to do this for new components?
1817
import { TextInputField } from "@matrix-org/react-sdk-module-api/lib/components/TextInputField";
1918
import { Spinner as ModuleSpinner } from "@matrix-org/react-sdk-module-api/lib/components/Spinner";
2019
import React from "react";
20+
2121
import Field from "../components/views/elements/Field";
2222
import Spinner from "../components/views/elements/Spinner";
2323

24+
// TODO: @@ Is this future-proof enough? Will we remember to do this for new components?
25+
2426
TextInputField.renderFactory = (props) => (
2527
<Field
2628
type="text"

src/modules/ModuleRunner.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ limitations under the License.
1515
*/
1616

1717
import { TranslationStringsObject } from "@matrix-org/react-sdk-module-api/lib/types/translations";
18+
import { AnyLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/types";
19+
1820
import { AppModule } from "./AppModule";
1921
import { ModuleFactory } from "./ModuleFactory";
20-
import { AnyLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/types";
2122
import "./ModuleComponents";
2223

24+
/**
25+
* Handles and coordinates the operation of modules.
26+
*/
2327
export class ModuleRunner {
2428
public static readonly instance = new ModuleRunner();
2529

@@ -29,6 +33,9 @@ export class ModuleRunner {
2933
// we only want one instance
3034
}
3135

36+
/**
37+
* All custom translations from all registered modules.
38+
*/
3239
public get allTranslations(): TranslationStringsObject {
3340
const merged: TranslationStringsObject = {};
3441

@@ -47,10 +54,20 @@ export class ModuleRunner {
4754
return merged;
4855
}
4956

57+
/**
58+
* Registers a factory which creates a module for later loading. The factory
59+
* will be called immediately.
60+
* @param factory The module factory.
61+
*/
5062
public registerModule(factory: ModuleFactory) {
5163
this.modules.push(new AppModule(factory));
5264
}
5365

66+
/**
67+
* Invokes a lifecycle event, notifying registered modules.
68+
* @param lifecycleEvent The lifecycle event.
69+
* @param args The arguments for the lifecycle event.
70+
*/
5471
public invoke(lifecycleEvent: AnyLifecycle, ...args: any[]): void {
5572
for (const module of this.modules) {
5673
module.module.emit(lifecycleEvent, ...args);

src/modules/ProxiedModuleApi.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,37 @@ import { MatrixClientPeg } from "../MatrixClientPeg";
3636
import { getCachedRoomIDForAlias } from "../RoomAliasCache";
3737
import { Action } from "../dispatcher/actions";
3838

39+
/**
40+
* Glue between the `ModuleApi` interface and the react-sdk. Anticipates one instance
41+
* to be assigned to a single module.
42+
*/
3943
export class ProxiedModuleApi implements ModuleApi {
4044
private cachedTranslations: Optional<TranslationStringsObject>;
4145

46+
/**
47+
* All custom translations used by the associated module.
48+
*/
4249
public get translations(): Optional<TranslationStringsObject> {
4350
return this.cachedTranslations;
4451
}
4552

53+
/**
54+
* @override
55+
*/
4656
public registerTranslations(translations: TranslationStringsObject): void {
4757
this.cachedTranslations = translations;
4858
}
4959

60+
/**
61+
* @override
62+
*/
5063
public translateString(s: string, variables?: Record<string, PlainSubstitution>): string {
5164
return _t(s, variables);
5265
}
5366

67+
/**
68+
* @override
69+
*/
5470
public openDialog<M extends object, P extends DialogProps = DialogProps, C extends React.Component = React.Component>(title: string, body: (props: P, ref: React.RefObject<C>) => React.ReactNode): Promise<{ didOkOrSubmit: boolean, model: M }> {
5571
return new Promise<{ didOkOrSubmit: boolean, model: M }>((resolve) => {
5672
Modal.createDialog(ModuleUiDialog, {
@@ -65,6 +81,9 @@ export class ProxiedModuleApi implements ModuleApi {
6581
});
6682
}
6783

84+
/**
85+
* @override
86+
*/
6887
public async registerSimpleAccount(username: string, password: string, displayName?: string): Promise<AccountAuthInfo> {
6988
const hsUrl = SdkConfig.get("validated_server_config").hsUrl;
7089
const client = Matrix.createClient({ baseUrl: hsUrl });
@@ -101,13 +120,19 @@ export class ProxiedModuleApi implements ModuleApi {
101120
};
102121
}
103122

123+
/**
124+
* @override
125+
*/
104126
public async overwriteAccountAuth(accountInfo: AccountAuthInfo): Promise<void> {
105127
await doSetLoggedIn({
106128
...accountInfo,
107129
guest: false,
108130
}, true);
109131
}
110132

133+
/**
134+
* @override
135+
*/
111136
public async navigatePermalink(uri: string, andJoin?: boolean): Promise<void> {
112137
navigateToPermalink(uri);
113138

@@ -139,6 +164,9 @@ export class ProxiedModuleApi implements ModuleApi {
139164
}
140165
}
141166

167+
/**
168+
* @override
169+
*/
142170
public getConfigValue<T>(namespace: string, key: string): T {
143171
// Force cast to `any` because the namespace won't be known to the SdkConfig types
144172
const maybeObj = SdkConfig.get(namespace as any);

src/stores/widgets/StopGapWidgetDriver.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import { WidgetType } from "../../widgets/WidgetType";
4646
import { CHAT_EFFECTS } from "../../effects";
4747
import { containsEmoji } from "../../effects/utils";
4848
import dis from "../../dispatcher/dispatcher";
49-
import { tryTransformPermalinkToLocalHref } from "../../utils/permalinks/Permalinks";
5049
import SettingsStore from "../../settings/SettingsStore";
5150
import { RoomViewStore } from "../RoomViewStore";
5251
import { ElementWidgetCapabilities } from "./ElementWidgetCapabilities";

0 commit comments

Comments
 (0)