@ydant/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ mount(App, document.getElementById("app")!, {
|
|
|
40
40
|
### Mount
|
|
41
41
|
|
|
42
42
|
```typescript
|
|
43
|
-
function mount(
|
|
43
|
+
function mount(app: Component, parent: HTMLElement, options?: MountOptions): void;
|
|
44
44
|
|
|
45
45
|
interface MountOptions {
|
|
46
46
|
plugins?: Plugin[];
|
|
@@ -51,39 +51,45 @@ interface MountOptions {
|
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
53
|
interface Plugin {
|
|
54
|
-
name: string;
|
|
55
|
-
types: string[];
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly types: readonly string[];
|
|
56
56
|
/** Plugin names that must be registered before this plugin */
|
|
57
|
-
dependencies?: string[];
|
|
57
|
+
readonly dependencies?: readonly string[];
|
|
58
58
|
/** Initialize plugin-specific properties in RenderContext */
|
|
59
|
-
initContext?(
|
|
59
|
+
initContext?(
|
|
60
|
+
ctx: RenderContextCore & Partial<RenderContextExtensions>,
|
|
61
|
+
parentCtx?: RenderContext,
|
|
62
|
+
): void;
|
|
60
63
|
/** Extend PluginAPI with plugin-specific methods */
|
|
61
|
-
extendAPI?(api:
|
|
62
|
-
/** Merge
|
|
63
|
-
mergeChildContext?(
|
|
64
|
+
extendAPI?(api: Partial<PluginAPIExtensions>, ctx: RenderContext): void;
|
|
65
|
+
/** Merge child context state into parent context (called after processChildren) */
|
|
66
|
+
mergeChildContext?(parentCtx: RenderContext, childCtx: RenderContext): void;
|
|
64
67
|
/** Process a child element */
|
|
65
68
|
process(child: Child, api: PluginAPI): PluginResult;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
interface PluginResult {
|
|
69
|
-
value?:
|
|
72
|
+
value?: ChildNext | undefined;
|
|
70
73
|
}
|
|
71
74
|
```
|
|
72
75
|
|
|
73
76
|
### Types
|
|
74
77
|
|
|
75
|
-
| Type
|
|
76
|
-
|
|
|
77
|
-
| `Tagged<T,P>`
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
78
|
+
| Type | Description |
|
|
79
|
+
| ---------------- | --------------------------------------------------------------------- |
|
|
80
|
+
| `Tagged<T,P>` | Helper type for tagged unions: `{ type: T } & P` |
|
|
81
|
+
| `CleanupFn` | `() => void` - Lifecycle cleanup function |
|
|
82
|
+
| `Child` | Union of all yieldable types (extended by plugins) |
|
|
83
|
+
| `ChildOfType<T>` | Extract a specific type from `Child` by tag |
|
|
84
|
+
| `ChildNext` | Union of values passed via `next()` (extended by plugins) |
|
|
85
|
+
| `ChildReturn` | Union of return values (extended by plugins) |
|
|
86
|
+
| `Builder` | `() => Instructor \| Instruction[]` - Element factory argument |
|
|
87
|
+
| `Instructor` | `Iterator<Child, ChildReturn, ChildNext>` - Internal iterator |
|
|
88
|
+
| `Instruction` | `Generator<Child, ChildReturn, ChildNext>` - Primitive return type |
|
|
89
|
+
| `Primitive<T>` | `Generator<T, void, void>` - Side-effect-only primitive return type |
|
|
90
|
+
| `ChildContent` | `Generator<Child, unknown, ChildNext>` - Children builder return type |
|
|
91
|
+
| `Render` | `Generator<Child, ChildReturn, ChildNext>` - Base rendering generator |
|
|
92
|
+
| `Component<P?>` | `() => Render` (no args) or `(props: P) => Render` (with props) |
|
|
87
93
|
|
|
88
94
|
### Plugin Extension Interfaces
|
|
89
95
|
|
|
@@ -164,21 +170,20 @@ export function createMyPlugin(): Plugin {
|
|
|
164
170
|
|
|
165
171
|
// Initialize context properties
|
|
166
172
|
initContext(ctx, parentCtx) {
|
|
167
|
-
ctx.myData = parentCtx?.myData
|
|
168
|
-
? new Map(parentCtx.myData as Map<string, unknown>)
|
|
169
|
-
: new Map();
|
|
173
|
+
ctx.myData = parentCtx?.myData ? new Map(parentCtx.myData) : new Map();
|
|
170
174
|
},
|
|
171
175
|
|
|
172
|
-
// Merge
|
|
173
|
-
mergeChildContext(
|
|
174
|
-
|
|
176
|
+
// Merge child context state into parent context
|
|
177
|
+
mergeChildContext(parentCtx, childCtx) {
|
|
178
|
+
for (const [key, value] of childCtx.myData) {
|
|
179
|
+
parentCtx.myData.set(key, value);
|
|
180
|
+
}
|
|
175
181
|
},
|
|
176
182
|
|
|
177
183
|
// Extend PluginAPI with methods
|
|
178
184
|
extendAPI(api, ctx) {
|
|
179
|
-
|
|
180
|
-
api.
|
|
181
|
-
api.setMyData = (key: string, value: unknown) => myData.set(key, value);
|
|
185
|
+
api.getMyData = (key: string) => ctx.myData.get(key);
|
|
186
|
+
api.setMyData = (key: string, value: unknown) => ctx.myData.set(key, value);
|
|
182
187
|
},
|
|
183
188
|
|
|
184
189
|
// Process child elements
|