-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathlegacy.js
46 lines (39 loc) · 966 Bytes
/
legacy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Legacy rendering core for svelte-testing-library.
*
* Supports Svelte <= 4.
*/
/** Allowed options for the component constructor. */
const allowedOptions = [
'target',
'accessors',
'anchor',
'props',
'hydrate',
'intro',
'context',
]
/**
* Mount the component into the DOM.
*
* The `onDestroy` callback is included for strict backwards compatibility
* with previous versions of this library. It's mostly unnecessary logic.
*/
const mount = (Component, options, onDestroy) => {
const component = new Component(options)
if (typeof onDestroy === 'function') {
component.$$.on_destroy.push(() => {
onDestroy(component)
})
}
return component
}
/** Remove the component from the DOM. */
const unmount = (component) => {
component.$destroy()
}
/** Update the component's props. */
const updateProps = (component, nextProps) => {
component.$set(nextProps)
}
export { allowedOptions, mount, unmount, updateProps }