@@ -4,7 +4,13 @@ import { tick } from 'svelte'
44const containerCache = new Map ( )
55const componentCache = new Set ( )
66
7- const svleteComponentOptions = [ 'anchor' , 'props' , 'hydrate' , 'intro' ]
7+ const svelteComponentOptions = [
8+ 'anchor' ,
9+ 'props' ,
10+ 'hydrate' ,
11+ 'intro' ,
12+ 'context'
13+ ]
814
915const render = (
1016 Component ,
@@ -17,19 +23,21 @@ const render = (
1723 const ComponentConstructor = Component . default || Component
1824
1925 const checkProps = ( options ) => {
20- const isProps = ! Object . keys ( options ) . some ( option => svleteComponentOptions . includes ( option ) )
26+ const isProps = ! Object . keys ( options ) . some ( ( option ) =>
27+ svelteComponentOptions . includes ( option )
28+ )
2129
2230 // Check if any props and Svelte options were accidentally mixed.
2331 if ( ! isProps ) {
24- const unrecognizedOptions = Object
25- . keys ( options )
26- . filter ( option => ! svleteComponentOptions . includes ( option ) )
32+ const unrecognizedOptions = Object . keys ( options ) . filter (
33+ ( option ) => ! svelteComponentOptions . includes ( option )
34+ )
2735
2836 if ( unrecognizedOptions . length > 0 ) {
2937 throw Error ( `
30- Unknown options were found [${ unrecognizedOptions } ]. This might happen if you've mixed
31- passing in props with Svelte options into the render function. Valid Svelte options
32- are [${ svleteComponentOptions } ]. You can either change the prop names, or pass in your
38+ Unknown options were found [${ unrecognizedOptions } ]. This might happen if you've mixed
39+ passing in props with Svelte options into the render function. Valid Svelte options
40+ are [${ svelteComponentOptions } ]. You can either change the prop names, or pass in your
3341 props for that component via the \`props\` option.\n\n
3442 Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n
3543 ` )
@@ -41,7 +49,7 @@ const render = (
4149 return { props : options }
4250 }
4351
44- const component = new ComponentConstructor ( {
52+ let component = new ComponentConstructor ( {
4553 target,
4654 ...checkProps ( options )
4755 } )
@@ -59,15 +67,15 @@ const render = (
5967 if ( componentCache . has ( component ) ) component . $destroy ( )
6068
6169 // eslint-disable-next-line no-new
62- const newComponent = new ComponentConstructor ( {
70+ component = new ComponentConstructor ( {
6371 target,
6472 ...checkProps ( options )
6573 } )
6674
67- containerCache . set ( container , { target, newComponent } )
68- componentCache . add ( newComponent )
75+ containerCache . set ( container , { target, component } )
76+ componentCache . add ( component )
6977
70- newComponent . $$ . on_destroy . push ( ( ) => { componentCache . delete ( newComponent ) } )
78+ component . $$ . on_destroy . push ( ( ) => { componentCache . delete ( component ) } )
7179 } ,
7280 unmount : ( ) => {
7381 if ( componentCache . has ( component ) ) component . $destroy ( )
@@ -76,7 +84,7 @@ const render = (
7684 }
7785}
7886
79- const cleanupAtContainer = container => {
87+ const cleanupAtContainer = ( container ) => {
8088 const { target, component } = containerCache . get ( container )
8189
8290 if ( componentCache . has ( component ) ) component . $destroy ( )
0 commit comments