Skip to content

Commit 63d496d

Browse files
authored
Merge pull request #240 from taras/refactor/usecontent-to-content
♻️ Migrate in-repo useContent() call sites to canonical content()
2 parents 33c40bd + c4606d6 commit 63d496d

14 files changed

Lines changed: 49 additions & 51 deletions

File tree

‎packages/core/src/components/Parse.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
import type { Operation } from "effection";
12-
import { useContent } from "../content-context.ts";
12+
import { content } from "../component-api.ts";
1313
import type { Json } from "../types.ts";
1414
import {
1515
ParseValidationError,
@@ -40,7 +40,7 @@ export const returns = {};
4040
export default function* (props: Record<string, Json>): Operation<Json> {
4141
const validate = compileParseSchema("Parse", props.schema);
4242

43-
const text = yield* useContent();
43+
const text = yield* content();
4444

4545
const parsed = parseText(text);
4646
if (!parsed.ok) {

‎packages/core/src/components/SafeParse.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import type { Operation } from "effection";
13-
import { useContent } from "../content-context.ts";
13+
import { content } from "../component-api.ts";
1414
import type { Json } from "../types.ts";
1515
import {
1616
compileParseSchema,
@@ -72,7 +72,7 @@ export const returns = {
7272
export default function* (props: Record<string, Json>): Operation<Json> {
7373
const validate = compileParseSchema("SafeParse", props.schema);
7474

75-
const text = yield* useContent();
75+
const text = yield* content();
7676

7777
const parsed = parseText(text);
7878
if (!parsed.ok) {

‎packages/core/src/components/TempDir.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { ReplayGuard, StaleInputError } from "@executablemd/durable-streams";
1616
import { mkdtempSync, realpathSync } from "node:fs";
1717
import { tmpdir } from "node:os";
1818
import { join } from "node:path";
19-
import { retain } from "../component-api.ts";
20-
import { hasContent, useContent } from "../content-context.ts";
19+
import { content, retain } from "../component-api.ts";
20+
import { hasContent } from "../content-context.ts";
2121

2222
export const props = {
2323
type: "object",
@@ -101,7 +101,7 @@ export default function* (): Operation<string> {
101101
{ at: "min" },
102102
);
103103
yield* refuseReplayInside(directory);
104-
return yield* useContent();
104+
return yield* content();
105105
}
106106
return yield* retain(useTemporaryDirectory);
107107
}

‎packages/core/src/content-context.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function useContent(slotName?: string): Operation<string> {
5050
* @example
5151
* ```ts
5252
* if (yield* hasContent()) {
53-
* return yield* useContent();
53+
* return yield* content();
5454
* }
5555
* ```
5656
*/

‎packages/core/src/expand.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ interface ProjectionState {
199199
/**
200200
* The environment projected content expands in. Undefined leaves the ambient
201201
* one in place, which is how a function component publishes bindings to its
202-
* own content: it installs an env and `useContent()` inherits it.
202+
* own content: it installs an env and `content()` inherits it.
203203
*/
204204
callerEnv: EvalEnv | undefined;
205205
meta: Record<string, unknown>;
@@ -1896,7 +1896,7 @@ function* expandFunctionComponent(
18961896
const siteLoop = yield* ActiveLoop.get();
18971897

18981898
// Call the function component inside its invocation, with content middleware
1899-
// in scope so it can render children via `yield* useContent()`.
1899+
// in scope so it can render its invocation content through `yield* content()`.
19001900
try {
19011901
const output = yield* withInvocation(function* (invocation) {
19021902
const enclosing = yield* ActiveProjection.get();

‎packages/core/tests/contextual-cwd.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { fileURLToPath } from "node:url";
3636
* resolution, invocation, projection — is the one being measured.
3737
*/
3838
const IN_DIRECTORY = [
39-
'import { useContent } from "@executablemd/core";',
39+
'import { content } from "@executablemd/core";',
4040
'import { API } from "@executablemd/runtime";',
4141
"",
4242
"export const props = {",
@@ -48,7 +48,7 @@ const IN_DIRECTORY = [
4848
"",
4949
"export default function*(props) {",
5050
" yield* API.Env.around({ *cwd() { return props.path; } }, { at: 'min' });",
51-
" return yield* useContent();",
51+
" return yield* content();",
5252
"}",
5353
].join("\n");
5454

‎packages/core/tests/expand.test.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { interpolate } from "../src/interpolate.ts";
88
import { validateProps, PropValidationError } from "../src/validate.ts";
99
import { renderSegments } from "../src/render.ts";
1010
import type { Operation } from "effection";
11-
import { useContent } from "../src/content-context.ts";
1211
import type {
1312
Segment,
1413
ComponentDefinition,
@@ -851,15 +850,15 @@ describe("interpolate", () => {
851850
});
852851

853852
describe("function component content", () => {
854-
it("renders default content and a named slot via useContent", function* () {
853+
it("renders default content and a named slot via content", function* () {
855854
const card: FunctionComponentDefinition = {
856855
kind: "function",
857856
name: "Card",
858857
path: "components/Card.ts",
859858
props: { type: "object", properties: {}, additionalProperties: false },
860859
*fn(_props) {
861-
const header = yield* useContent("header");
862-
const body = yield* useContent();
860+
const header = yield* content("header");
861+
const body = yield* content();
863862
return `[${header.trim()}|${body.trim()}]`;
864863
},
865864
};

‎packages/core/tests/invocation-scope.test.ts‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import { describe, it } from "@executablemd/test-support/bdd";
1010
import { expect } from "@executablemd/test-support/expect";
1111
import { race, scoped, sleep } from "effection";
1212
import { useEvalScope } from "@effectionx/scope-eval";
13-
import { Component } from "../src/component-api.ts";
13+
import { Component, content } from "../src/component-api.ts";
1414
import { expandSegments } from "../src/expand.ts";
1515
import { renderSegments } from "../src/render.ts";
1616
import { scanSegments } from "../src/scanner.ts";
17-
import { useContent } from "../src/content-context.ts";
1817
import {
1918
BOOM_BLOCK,
2019
component,
@@ -48,7 +47,7 @@ describe("Tier O — Eval scope hierarchy", () => {
4847
Probe: component("Probe", () =>
4948
(function* () {
5049
yield* useWatch(timeline, "own");
51-
return yield* useContent();
50+
return yield* content();
5251
})(),
5352
),
5453
};
@@ -69,7 +68,7 @@ describe("Tier O — Eval scope hierarchy", () => {
6968
Probe: component("Probe", () =>
7069
(function* () {
7170
yield* useWatch(timeline, "own");
72-
return yield* useContent();
71+
return yield* content();
7372
})(),
7473
),
7574
};
@@ -86,9 +85,9 @@ describe("Tier O — Eval scope hierarchy", () => {
8685
const definitions = {
8786
Probe: component("Probe", () =>
8887
(function* () {
89-
const content = yield* useContent();
88+
const projected = yield* content();
9089
yield* useWatch(timeline, "own");
91-
return content;
90+
return projected;
9291
})(),
9392
),
9493
};
@@ -105,7 +104,7 @@ describe("Tier O — Eval scope hierarchy", () => {
105104
Probe: component("Probe", () =>
106105
(function* () {
107106
yield* useWatch(timeline, "own");
108-
return yield* useContent();
107+
return yield* content();
109108
})(),
110109
),
111110
};
@@ -129,7 +128,7 @@ describe("Tier O — Eval scope hierarchy", () => {
129128
Probe: component("Probe", () =>
130129
(function* () {
131130
yield* useWatch(timeline, "own", true);
132-
return yield* useContent();
131+
return yield* content();
133132
})(),
134133
),
135134
};
@@ -178,7 +177,7 @@ describe("Tier O — Eval scope hierarchy", () => {
178177
Probe: component("Probe", () =>
179178
(function* () {
180179
yield* useWatch(timeline, "own");
181-
yield* useContent();
180+
yield* content();
182181
throw new Error("body exploded");
183182
})(),
184183
),
@@ -212,7 +211,7 @@ describe("Tier O — Eval scope hierarchy", () => {
212211
Probe: component("Probe", () =>
213212
(function* () {
214213
yield* useWatch(timeline, "own");
215-
return yield* useContent();
214+
return yield* content();
216215
})(),
217216
),
218217
};
@@ -229,13 +228,13 @@ describe("Tier O — Eval scope hierarchy", () => {
229228
Outer: component("Outer", () =>
230229
(function* () {
231230
yield* useWatch(timeline, "outer");
232-
return yield* useContent();
231+
return yield* content();
233232
})(),
234233
),
235234
Inner: component("Inner", () =>
236235
(function* () {
237236
yield* useWatch(timeline, "inner");
238-
return yield* useContent();
237+
return yield* content();
239238
})(),
240239
),
241240
};

‎packages/core/tests/loop.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ describe("Tier BREAK — the projection boundary", () => {
15211521
expect(output.match(/TAIL/g)).toHaveLength(2);
15221522
});
15231523

1524-
it("BREAK22: a projected <Break> reaches a loop through useContent() too", function* () {
1524+
it("BREAK22: a projected <Break> reaches a loop through content() too", function* () {
15251525
const output = yield* runDoc("<Loop max={3}>HEAD<TempDir><Break /></TempDir>TAIL</Loop>", {});
15261526

15271527
expect(output).not.toContain("TAIL");

‎packages/core/tests/retain.test.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import { Component } from "../src/component-api.ts";
1616
import { expandSegments } from "../src/expand.ts";
1717
import { renderSegments } from "../src/render.ts";
1818
import { scanSegments } from "../src/scanner.ts";
19-
import { useContent } from "../src/content-context.ts";
20-
import { retain } from "../src/component-api.ts";
19+
import { content, retain } from "../src/component-api.ts";
2120
import {
2221
component,
2322
expandAll,
@@ -64,7 +63,7 @@ describe("Tier RT — Retained resources", () => {
6463
Reader: component("Reader", () =>
6564
(function* () {
6665
observed.push(timeline.includes("stop:dir") ? "released" : "live");
67-
return yield* useContent();
66+
return yield* content();
6867
})(),
6968
),
7069
};
@@ -161,7 +160,7 @@ describe("Tier RT — Retained resources", () => {
161160
Outer: component("Outer", () =>
162161
(function* () {
163162
yield* useWatch(timeline, "outer");
164-
return yield* useContent();
163+
return yield* content();
165164
})(),
166165
),
167166
Inner: retainer("Inner", timeline, "inner-retained"),
@@ -297,7 +296,7 @@ describe("Tier RT — Site isolation", () => {
297296
Outer: component("Outer", () =>
298297
(function* (): Operation<string> {
299298
yield* Marker.set("from-caller");
300-
return yield* useContent();
299+
return yield* content();
301300
})(),
302301
),
303302
// Installs both kinds of scope mutation, then hands back a value.
@@ -322,7 +321,7 @@ describe("Tier RT — Site isolation", () => {
322321
Reader: component("Reader", () =>
323322
(function* (): Operation<string> {
324323
observed.push(yield* Marker.get());
325-
return yield* useContent();
324+
return yield* content();
326325
})(),
327326
),
328327
};

0 commit comments

Comments
 (0)