refactor: revert some style changes and clean some code
This commit is contained in:
parent
53d6d57854
commit
0d97d5bd49
|
|
@ -31,11 +31,7 @@ import { createRawSnippet } from "svelte";
|
||||||
* @returns {component is ObjectComponent}
|
* @returns {component is ObjectComponent}
|
||||||
*/
|
*/
|
||||||
function isObjectComponent(component) {
|
function isObjectComponent(component) {
|
||||||
return (
|
return typeof component === 'object' && component && component.__pw_type === 'object-component';
|
||||||
typeof component === 'object' &&
|
|
||||||
component &&
|
|
||||||
component.__pw_type === 'object-component'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {( component: ObjectComponent ) => Record<string, any>} */
|
/** @type {( component: ObjectComponent ) => Record<string, any>} */
|
||||||
|
|
@ -59,7 +55,7 @@ function extractParams(component) {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
return {props, slots, on};
|
return {...props, ...slots, ...on};
|
||||||
}
|
}
|
||||||
|
|
||||||
const __pwSvelteComponentKey = Symbol('svelteComponent');
|
const __pwSvelteComponentKey = Symbol('svelteComponent');
|
||||||
|
|
@ -75,15 +71,9 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||||
if (!isObjectComponent(component))
|
if (!isObjectComponent(component))
|
||||||
throw new Error('JSX mount notation is not supported');
|
throw new Error('JSX mount notation is not supported');
|
||||||
|
|
||||||
let {props, slots, on} = extractParams(component);
|
|
||||||
|
|
||||||
super({
|
super({
|
||||||
target: rootElement,
|
target: rootElement,
|
||||||
props: {
|
props: extractParams(component),
|
||||||
...props,
|
|
||||||
...slots,
|
|
||||||
...on,
|
|
||||||
},
|
|
||||||
...options
|
...options
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -106,10 +96,9 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
window.playwrightUnmount = async rootElement => {
|
window.playwrightUnmount = async rootElement => {
|
||||||
const svelteComponent = /** @type {SvelteComponent} */ (
|
const svelteComponent = /** @type {SvelteComponent} */ (rootElement[__pwSvelteComponentKey]);
|
||||||
rootElement[__pwSvelteComponentKey]
|
if (!svelteComponent)
|
||||||
);
|
throw new Error('Component was not mounted');
|
||||||
if (!svelteComponent) throw new Error('Component was not mounted');
|
|
||||||
svelteComponent.$destroy();
|
svelteComponent.$destroy();
|
||||||
delete rootElement[__pwSvelteComponentKey];
|
delete rootElement[__pwSvelteComponentKey];
|
||||||
};
|
};
|
||||||
|
|
@ -118,16 +107,9 @@ window.playwrightUpdate = async (rootElement, component) => {
|
||||||
if (!isObjectComponent(component))
|
if (!isObjectComponent(component))
|
||||||
throw new Error('JSX mount notation is not supported');
|
throw new Error('JSX mount notation is not supported');
|
||||||
|
|
||||||
const svelteComponent = /** @type {SvelteComponent} */ (
|
const svelteComponent = /** @type {SvelteComponent} */ (rootElement[__pwSvelteComponentKey]);
|
||||||
rootElement[__pwSvelteComponentKey]
|
if (!svelteComponent)
|
||||||
);
|
throw new Error('Component was not mounted');
|
||||||
if (!svelteComponent) throw new Error('Component was not mounted');
|
|
||||||
|
|
||||||
let {props, slots, on} = extractParams(component);
|
svelteComponent.$set(extractParams(component));
|
||||||
|
|
||||||
svelteComponent.$set({
|
|
||||||
...props,
|
|
||||||
...slots,
|
|
||||||
...on,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue