Skip to content

Commit 6575653

Browse files
bloveclaude
andauthored
docs(render): fix snippet accuracy vs 0.0.49 API (#645)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 42aa904 commit 6575653

5 files changed

Lines changed: 42 additions & 17 deletions

File tree

apps/website/content/docs/render/api/define-angular-registry.mdx

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,26 @@ import { defineAngularRegistry } from '@threadplane/render';
1212

1313
```typescript
1414
function defineAngularRegistry(
15-
componentMap: Record<string, AngularComponentRenderer>,
15+
componentMap: Record<string, AngularComponentRenderer | RenderViewEntry>,
1616
): AngularRegistry;
1717
```
1818

1919
### Parameters
2020

2121
| Parameter | Type | Description |
2222
|-----------|------|-------------|
23-
| `componentMap` | `Record<string, AngularComponentRenderer>` | An object mapping type name strings to Angular component classes |
23+
| `componentMap` | `Record<string, AngularComponentRenderer \| RenderViewEntry>` | An object mapping type name strings to Angular component classes, or to `{ component, fallback? }` objects |
2424

25-
`AngularComponentRenderer` is defined as `Type<unknown>` -- any Angular component class.
25+
`AngularComponentRenderer` is defined as `Type<unknown>` -- any Angular component class. Each entry can be a bare component class or a `RenderViewEntry` object:
26+
27+
```typescript
28+
interface RenderViewEntry {
29+
component: AngularComponentRenderer;
30+
fallback?: AngularComponentRenderer;
31+
}
32+
```
33+
34+
Use the object form to configure a custom per-entry fallback (see [Per-Component Fallbacks](#per-component-fallbacks) below). A bare component class is shorthand for `{ component }` paired with the library's default fallback.
2635

2736
### Returns
2837

@@ -118,15 +127,33 @@ An entry that omits `fallback` -- including every bare-component entry like `Tex
118127

119128
## Internal Behavior
120129

121-
The function converts the input object to an internal `Map<string, AngularComponentRenderer>` for O(1) lookups:
130+
The function normalizes each input entry into a `{ component, fallback }` pair and stores them in an internal `Map` for O(1) lookups. A bare component class is paired with `DefaultFallbackComponent`; an object entry keeps its own `fallback` or falls back to the default:
122131

123132
```typescript
133+
function normalize(
134+
entry: AngularComponentRenderer | RenderViewEntry,
135+
): NormalizedEntry {
136+
// Bare Type — register with the default fallback.
137+
if (typeof entry === 'function') {
138+
return { component: entry, fallback: DefaultFallbackComponent };
139+
}
140+
// Object form — preserve component; use configured fallback or default.
141+
return {
142+
component: entry.component,
143+
fallback: entry.fallback ?? DefaultFallbackComponent,
144+
};
145+
}
146+
124147
function defineAngularRegistry(
125-
componentMap: Record<string, AngularComponentRenderer>,
148+
componentMap: Record<string, AngularComponentRenderer | RenderViewEntry>,
126149
): AngularRegistry {
127-
const map = new Map(Object.entries(componentMap));
150+
const map = new Map<string, NormalizedEntry>();
151+
for (const [name, entry] of Object.entries(componentMap)) {
152+
map.set(name, normalize(entry));
153+
}
128154
return {
129-
get: (name: string) => map.get(name),
155+
get: (name: string) => map.get(name)?.component,
156+
getFallback: (name: string) => map.get(name)?.fallback,
130157
names: () => [...map.keys()],
131158
};
132159
}

apps/website/content/docs/render/api/provide-render.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface RenderConfig {
3939
|----------|------|-------------|
4040
| `registry` | `AngularRegistry` | Default component registry for all `<render-spec>` instances |
4141
| `store` | `StateStore` | Default state store for all `<render-spec>` instances |
42-
| `functions` | `Record<string, ComputedFunction>` | Default computed functions for `$fn` prop expressions |
42+
| `functions` | `Record<string, ComputedFunction>` | Default computed functions for `$computed` prop expressions |
4343
| `handlers` | `Record<string, Handler>` | Default event handlers for action dispatch |
4444

4545
All properties are optional. Only provide the defaults you need.

apps/website/content/docs/render/api/render-spec-component.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class MyComponent {
3838
| `spec` | `Spec \| null` | `null` | The json-render spec to render. When `null`, nothing is rendered. |
3939
| `registry` | `AngularRegistry \| undefined` | `undefined` | Component registry mapping element types to Angular components. |
4040
| `store` | `StateStore \| undefined` | `undefined` | State store for reactive prop resolution. |
41-
| `functions` | `Record<string, ComputedFunction> \| undefined` | `undefined` | Computed functions for `$fn` prop expressions. |
41+
| `functions` | `Record<string, ComputedFunction> \| undefined` | `undefined` | Computed functions for `$computed` prop expressions. |
4242
| `handlers` | `Record<string, (params: Record<string, unknown>) => unknown \| Promise<unknown>> \| undefined` | `undefined` | Event handlers invoked when components call `emit()`. |
4343
| `loading` | `boolean` | `false` | Whether the spec is currently streaming. Passed to all rendered components as the `loading` input. |
4444

apps/website/content/docs/render/getting-started/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The library resolves `Text` from your component registry, evaluates the `$state`
2929

3030
## How It Relates to @json-render/core
3131

32-
`@json-render/core` provides the spec format and the evaluation engine -- it resolves prop expressions (`$state`, `$item`, `$index`, `$bindState`, `$fn`), evaluates visibility conditions, and resolves bindings. It is framework-agnostic and has no Angular dependency.
32+
`@json-render/core` provides the spec format and the evaluation engine -- it resolves prop expressions (`$state`, `$item`, `$index`, `$bindState`, `$computed`), evaluates visibility conditions, and resolves bindings. It is framework-agnostic and has no Angular dependency.
3333

3434
`@threadplane/render` is the Angular adapter layer. It provides:
3535

apps/website/content/docs/render/guides/specs.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,20 @@ props: {
110110
}
111111
```
112112

113-
### $fn -- Computed Function
113+
### $computed -- Computed Function
114114

115115
Calls a registered computed function with the given arguments:
116116

117117
```typescript
118118
props: {
119119
label: {
120-
$fn: {
121-
name: 'uppercase',
122-
args: { text: { $state: '/name' } }
123-
}
120+
$computed: 'uppercase',
121+
args: { text: { $state: '/name' } }
124122
},
125123
}
126124
```
127125

128-
The `name` references a function you register in a `functions` map. Each function is a `ComputedFunction` from `@json-render/core` -- `(args: Record<string, unknown>) => unknown`. The `args` object is resolved first (so `{ $state: '/name' }` becomes the current value at `/name`), then passed to your function:
126+
The `$computed` value names a function you register in a `functions` map. Each function is a `ComputedFunction` from `@json-render/core` -- `(args: Record<string, unknown>) => unknown`. The `args` object is resolved first (so `{ $state: '/name' }` becomes the current value at `/name`), then passed to your function:
129127

130128
```typescript
131129
import type { ComputedFunction } from '@json-render/core';
@@ -154,7 +152,7 @@ provideRender({
154152
});
155153
```
156154

157-
With either wiring, the `$fn` expression above resolves `label` to the uppercased value of `/name`. The input takes priority over the `provideRender()` config when both are present.
155+
With either wiring, the `$computed` expression above resolves `label` to the uppercased value of `/name`. The input takes priority over the `provideRender()` config when both are present.
158156

159157
## Children
160158

0 commit comments

Comments
 (0)