@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.
Files changed (2) hide show
  1. package/README.md +35 -30
  2. 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(component: Component, container: HTMLElement, options?: MountOptions): void;
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?(ctx: Record<string, unknown>, parentCtx?: Record<string, unknown>): void;
59
+ initContext?(
60
+ ctx: RenderContextCore & Partial<RenderContextExtensions>,
61
+ parentCtx?: RenderContext,
62
+ ): void;
60
63
  /** Extend PluginAPI with plugin-specific methods */
61
- extendAPI?(api: Record<string, unknown>, ctx: Record<string, unknown>): void;
62
- /** Merge parent context into child context (called when creating child contexts) */
63
- mergeChildContext?(childCtx: Record<string, unknown>, parentCtx: Record<string, unknown>): void;
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?: unknown; // Value to pass back via next()
72
+ value?: ChildNext | undefined;
70
73
  }
71
74
  ```
72
75
 
73
76
  ### Types
74
77
 
75
- | Type | Description |
76
- | ------------------ | --------------------------------------------------------------------- |
77
- | `Tagged<T,P>` | Helper type for tagged unions: `{ type: T } & P` |
78
- | `Child` | Union of all yieldable types (extended by plugins) |
79
- | `ChildNext` | Union of values passed via `next()` (extended by plugins) |
80
- | `ChildReturn` | Union of return values (extended by plugins) |
81
- | `Render` | `Generator<Child, ChildReturn, ChildNext>` - Base rendering generator |
82
- | `Component` | `() => Render` - Root component type |
83
- | `ComponentWith<P>` | `(props: P) => Render` - Component type with props |
84
- | `Builder` | `() => Instructor \| Instruction[]` - Element factory argument |
85
- | `Instructor` | `Iterator<Child, ChildReturn, ChildNext>` - Internal iterator |
86
- | `Instruction` | `Generator<Child, ChildReturn, ChildNext>` - Primitive return type |
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 parent context into child context
173
- mergeChildContext(childCtx, parentCtx) {
174
- childCtx.myData = new Map(parentCtx.myData as Map<string, unknown>);
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
- const myData = ctx.myData as Map<string, unknown>;
180
- api.getMyData = (key: string) => myData.get(key);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ydant/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Generator-based DOM rendering DSL",
5
5
  "keywords": [
6
6
  "dsl",