fix: rax finddom 方法重写

This commit is contained in:
响指 2020-08-19 15:09:05 +08:00
parent 4642f2dd99
commit 1d9092855c

View File

@ -188,8 +188,23 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer {
cursor.release();
}
findDOMNodes(instance: any): Array<Element | Text> | null {
return [raxFindDOMNodes(instance)];
findDOMNodes(instance: any, selector?: string): Array<Element | Text> | null {
let el = instance;
if (selector) {
el = document.querySelector(selector);
}
try {
return raxFindDOMNodes(el);
} catch (e) {
// ignore
}
if (el && el.type && el.props && el.props.componentId) {
el = document.querySelector(`${el.type}[componentid=${el.props.componentId}]`);
} else {
console.error(instance);
throw new Error('This instance may not a valid element');
}
return raxFindDOMNodes(el);
}
/**