@@ -4,7 +4,13 @@ import { tick } from 'svelte'
4
4
const containerCache = new Map ( )
5
5
const componentCache = new Set ( )
6
6
7
- const svleteComponentOptions = [ 'anchor' , 'props' , 'hydrate' , 'intro' ]
7
+ const svelteComponentOptions = [
8
+ 'anchor' ,
9
+ 'props' ,
10
+ 'hydrate' ,
11
+ 'intro' ,
12
+ 'context'
13
+ ]
8
14
9
15
const render = (
10
16
Component ,
@@ -17,19 +23,21 @@ const render = (
17
23
const ComponentConstructor = Component . default || Component
18
24
19
25
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
+ )
21
29
22
30
// Check if any props and Svelte options were accidentally mixed.
23
31
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
+ )
27
35
28
36
if ( unrecognizedOptions . length > 0 ) {
29
37
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
33
41
props for that component via the \`props\` option.\n\n
34
42
Eg: const { /** Results **/ } = render(MyComponent, { props: { /** props here **/ } })\n\n
35
43
` )
@@ -41,7 +49,7 @@ const render = (
41
49
return { props : options }
42
50
}
43
51
44
- const component = new ComponentConstructor ( {
52
+ let component = new ComponentConstructor ( {
45
53
target,
46
54
...checkProps ( options )
47
55
} )
@@ -59,15 +67,15 @@ const render = (
59
67
if ( componentCache . has ( component ) ) component . $destroy ( )
60
68
61
69
// eslint-disable-next-line no-new
62
- const newComponent = new ComponentConstructor ( {
70
+ component = new ComponentConstructor ( {
63
71
target,
64
72
...checkProps ( options )
65
73
} )
66
74
67
- containerCache . set ( container , { target, newComponent } )
68
- componentCache . add ( newComponent )
75
+ containerCache . set ( container , { target, component } )
76
+ componentCache . add ( component )
69
77
70
- newComponent . $$ . on_destroy . push ( ( ) => { componentCache . delete ( newComponent ) } )
78
+ component . $$ . on_destroy . push ( ( ) => { componentCache . delete ( component ) } )
71
79
} ,
72
80
unmount : ( ) => {
73
81
if ( componentCache . has ( component ) ) component . $destroy ( )
@@ -76,7 +84,7 @@ const render = (
76
84
}
77
85
}
78
86
79
- const cleanupAtContainer = container => {
87
+ const cleanupAtContainer = ( container ) => {
80
88
const { target, component } = containerCache . get ( container )
81
89
82
90
if ( componentCache . has ( component ) ) component . $destroy ( )
0 commit comments