File tree Expand file tree Collapse file tree 4 files changed +14
-11
lines changed
tests/runtime-runes/samples Expand file tree Collapse file tree 4 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ export function wrap_snippet(component, fn) {
67
67
* @param {{
68
68
* mount: (...params: any[]) => Element,
69
69
* hydrate?: (element: Element, ...params: any[]) => void,
70
- * render: (...params: any[]) => string
70
+ * render: (...params: any[]) => { head: string, body: string }
71
71
* }} options
72
72
*/
73
73
export function createRawSnippet ( { mount, hydrate } ) {
Original file line number Diff line number Diff line change @@ -160,12 +160,18 @@ export function head(payload, fn) {
160
160
* @param {{
161
161
* mount: (...params: any[]) => Element,
162
162
* hydrate?: (element: Element, ...params: any[]) => void,
163
- * render: (...params: any[]) => string
163
+ * render: (...params: any[]) => { head: string, body: string }
164
164
* }} options
165
165
*/
166
166
export function createRawSnippet ( { render } ) {
167
167
const snippet_fn = ( /** @type {Payload } */ payload , /** @type {any[] } */ ...args ) => {
168
- payload . out += render ( ...args ) ;
168
+ const { head, body } = render ( ...args ) ;
169
+ if ( body ) {
170
+ payload . out += body ;
171
+ }
172
+ if ( head ) {
173
+ payload . head . out += body ;
174
+ }
169
175
} ;
170
176
add_snippet_symbol ( snippet_fn ) ;
171
177
return snippet_fn ;
Original file line number Diff line number Diff line change 1
1
<script >
2
- import { createRawSnippet } from ' svelte' ;
2
+ import { createRawSnippet } from ' svelte' ;
3
3
4
4
let count = $state (0 );
5
5
14
14
return div;
15
15
},
16
16
hydrate (element , count ) {
17
-
18
17
$effect (() => {
19
18
element .textContent = count ();
20
19
});
21
-
22
20
},
23
21
render (count ) {
24
- return ` <div>${ count} </div>` ;
22
+ return { body : ` <div>${ count} </div>` } ;
25
23
}
26
24
});
27
25
</script >
28
26
29
- <div >
30
- {@render snippet (count )}
31
- </div >
27
+ {@render snippet (count )}
28
+
32
29
<button onclick ={() => count ++ }>+</button >
Original file line number Diff line number Diff line change 8
8
return p;
9
9
},
10
10
render () {
11
- return ' <p>hello world</p>' ;
11
+ return { body : ' <p>hello world</p>' } ;
12
12
}
13
13
});
14
14
</script >
You can’t perform that action at this time.
0 commit comments