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

Commit 8add540

Browse files
Document what all of our "Pegs" are (just singletons) (#8510)
As discussed at https://matrix.to/#/!fLeHeojWgBGJlLNdLC:matrix.org/$DHCPeZQ1aty_1l_nNHo_5F8Uwb3t29N1zuabWa5qLzM?via=matrix.org&via=element.io&via=vector.modular.im Peg is used in the literal sense: > a short pin or bolt, typically tapered at one end, that is used for securing something in place, hanging things on, or marking a position. Looking for an `MatrixClient`? Just look for the `MatrixClientPeg` on the peg board. So you'll find a `MatrixClient` hanging on the `MatrixClientPeg`. Maybe you're more familiar with these alternative names like `MatrixClientSingleton` but that's a bit long and Java-y or `MatrixClientHandle` in the win32 world.
1 parent 3a241e0 commit 8add540

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/MatrixClientPeg.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ export interface IMatrixClientCreds {
4949
freshLogin?: boolean;
5050
}
5151

52+
/**
53+
* Holds the current instance of the `MatrixClient` to use across the codebase.
54+
* Looking for an `MatrixClient`? Just look for the `MatrixClientPeg` on the peg
55+
* board. "Peg" is the literal meaning of something you hang something on. So
56+
* you'll find a `MatrixClient` hanging on the `MatrixClientPeg`.
57+
*/
5258
export interface IMatrixClientPeg {
5359
opts: IStartClientOpts;
5460

@@ -311,6 +317,10 @@ class MatrixClientPegClass implements IMatrixClientPeg {
311317
}
312318
}
313319

320+
/**
321+
* Note: You should be using a React context with access to a client rather than
322+
* using this, as in a multi-account world this will not exist!
323+
*/
314324
export const MatrixClientPeg: IMatrixClientPeg = new MatrixClientPegClass();
315325

316326
if (!window.mxMatrixClientPeg) {

src/PlatformPeg.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ limitations under the License.
1818
import BasePlatform from "./BasePlatform";
1919

2020
/*
21-
* Holds the current Platform object used by the code to do anything
22-
* specific to the platform we're running on (eg. web, electron)
23-
* Platforms are provided by the app layer.
24-
* This allows the app layer to set a Platform without necessarily
25-
* having to have a MatrixChat object
21+
* Holds the current instance of the `Platform` to use across the codebase.
22+
* Looking for an `Platform`? Just look for the `PlatformPeg` on the peg board.
23+
* "Peg" is the literal meaning of something you hang something on. So you'll
24+
* find a `Platform` hanging on the `PlatformPeg`.
25+
*
26+
* Used by the code to do anything specific to the platform we're running on
27+
* (eg. web, electron). Platforms are provided by the app layer. This allows the
28+
* app layer to set a Platform without necessarily having to have a MatrixChat
29+
* object.
2630
*/
2731
export class PlatformPeg {
2832
platform: BasePlatform = null;

src/indexing/EventIndexPeg.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import { SettingLevel } from "../settings/SettingLevel";
2929

3030
const INDEX_VERSION = 1;
3131

32+
/**
33+
* Holds the current instance of the `EventIndex` to use across the codebase.
34+
* Looking for an `EventIndex`? Just look for the `EventIndexPeg` on the peg
35+
* board. "Peg" is the literal meaning of something you hang something on. So
36+
* you'll find a `EventIndex` hanging on the `EventIndexPeg`.
37+
*/
3238
export class EventIndexPeg {
3339
public index: EventIndex = null;
3440
public error: Error = null;

0 commit comments

Comments
 (0)