|
| 1 | +Solutions for Rune-Based Reactive State Sharing |
| 2 | + |
| 3 | +Solution 1: Reactive Context Injection |
| 4 | + |
| 5 | +Modify the factory function to accept reactive context objects that get injected into the |
| 6 | +component's compilation scope. Instead of passing static values, pass rune references directly |
| 7 | +through the compilation process. |
| 8 | + |
| 9 | +Approach: |
| 10 | +- Extend ComponentCompiler.render() to accept a reactiveContext parameter containing rune |
| 11 | +objects |
| 12 | +- Modify transformCompiledCode() to inject these runes as imports/globals in the compiled |
| 13 | +component |
| 14 | +- The dynamic component accesses parent runes directly via injected context |
| 15 | + |
| 16 | +Solution 2: Rune Reference Passing |
| 17 | + |
| 18 | +Create a mechanism to pass actual rune references (not their values) through the mount system by |
| 19 | + serializing rune getters/setters and reconstructing them in the dynamic component. |
| 20 | + |
| 21 | +Approach: |
| 22 | +- Extend the factory function to accept rune descriptors ({ get: () => value, set: (v) => {...} |
| 23 | +}) |
| 24 | +- Transform the compiled code to wire these descriptors to local rune state |
| 25 | +- Dynamic components get direct access to parent runes through the descriptor interface |
| 26 | + |
| 27 | +Solution 3: Shared Rune Store |
| 28 | + |
| 29 | +Implement a global rune store that both parent and dynamic components can subscribe to, using |
| 30 | +Svelte 5's $state() with a singleton pattern. |
| 31 | + |
| 32 | +Approach: |
| 33 | +- Create a SharedRuneStore class with $state() values |
| 34 | +- Parent components register their runes in the store |
| 35 | +- Dynamic components access the same rune references from the store |
| 36 | +- No wrapper/proxy - direct rune access through shared state container |
| 37 | + |
| 38 | +Solution 4: Compilation-Time Rune Binding |
| 39 | + |
| 40 | +Modify the source transformation to replace rune references in the dynamic component with |
| 41 | +bindings to externally provided rune objects. |
| 42 | + |
| 43 | +Approach: |
| 44 | +- Parse the dynamic component source for rune usage patterns |
| 45 | +- Replace let { count = $bindable(0) } = $props() with direct external rune bindings |
| 46 | +- Inject the actual parent runes as module-level imports during compilation |
| 47 | +- Component uses parent runes as if they were its own |
0 commit comments