Skip to content

Commit b4afd87

Browse files
committed
Rename engine state const for clarity
1 parent 443f88e commit b4afd87

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

demo/README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@ Each example shows:
2020

2121
## Usage
2222

23+
(all commands should be run in the root directory of the project)
24+
2325
1. Make sure the project is built:
2426
```bash
2527
npm run build:all
2628
```
2729

28-
2. Open `index.html` in a web browser. You can:
29-
- Simply open the file directly in your browser
30-
- Or use a local web server (recommended) by executing the following command in the root directory of the project:
31-
```bash
32-
# Using Python
33-
python -m http.server 8000
34-
35-
# Using NodeJS
36-
npx http-server -p 8000
37-
```
38-
Then navigate to `http://localhost:8000/demo/`
30+
2. Start up a local web server:
31+
```bash
32+
npx http-server -p 8000
33+
```
34+
35+
3. Navigate to `http://localhost:8000/demo/`
3936

src/engine.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ type InternalState = {
66
adapters: Record<string, (raw: string, code?: string) => Trace | null>;
77
};
88

9-
const S: InternalState = { adapters: {} };
9+
const state: InternalState = { adapters: {} };
1010

11-
export const loadCopydeck = (deck: CopyDeck) => (S.copy = deck);
11+
export const loadCopydeck = (deck: CopyDeck) => (state.copy = deck);
1212

1313
const getUiString = (key: keyof NonNullable<CopyDeck["ui"]>, fallback: string): string => {
14-
return S.copy?.ui?.[key] || fallback;
14+
return state.copy?.ui?.[key] || fallback;
1515
};
1616

1717
export const registerAdapter = (name: string, fn: (raw: string, code?: string) => Trace | null) =>
18-
(S.adapters[name] = fn);
18+
(state.adapters[name] = fn);
1919

2020
const coerceTrace = (input: string | Error | Trace, code?: string): Trace => {
2121
if ((input as Trace).raw !== undefined) return input as Trace;
2222
const raw = typeof input === "string" ? input : String((input as Error).stack || (input as Error).message || input);
2323
// try adapters in registration order
24-
for (const key of Object.keys(S.adapters)) {
25-
const t = S.adapters[key](raw, code);
24+
for (const key of Object.keys(state.adapters)) {
25+
const t = state.adapters[key](raw, code);
2626
if (t) return t;
2727
}
2828
// generic fallback
@@ -42,7 +42,7 @@ const coerceTrace = (input: string | Error | Trace, code?: string): Trace => {
4242
};
4343

4444
const pickVariant = (trace: Trace, code: string | undefined, audience: string) => {
45-
const deck = S.copy;
45+
const deck = state.copy;
4646
const kind = trace.type && deck?.errors[trace.type] ? trace.type : "Other";
4747
const entry = deck?.errors[kind];
4848
if (!entry) return null;
@@ -78,7 +78,7 @@ const pickVariant = (trace: Trace, code: string | undefined, audience: string) =
7878
const v = entry.variants[i];
7979
if (!matches(v)) continue;
8080

81-
const glob = S.copy?.glossary?.[audience] || undefined;
81+
const glob = state.copy?.glossary?.[audience] || undefined;
8282
const title = applyGlossary(tmpl(v.title, vars), glob);
8383
const summary = applyGlossary(tmpl(v.summary, vars), glob);
8484
const why = v.why ? applyGlossary(tmpl(v.why, vars), glob) : undefined;
@@ -122,7 +122,7 @@ const pickVariant = (trace: Trace, code: string | undefined, audience: string) =
122122
};
123123

124124
export const friendlyExplain = (opts: ExplainOptions): ExplainResult => {
125-
if (!S.copy) throw new Error("Copydeck not loaded");
125+
if (!state.copy) throw new Error("Copydeck not loaded");
126126
const audience = opts.audience || "beginner";
127127
const verbosity = opts.verbosity || "standard";
128128
const code = opts.code;

0 commit comments

Comments
 (0)