From 55bd06a5ee9468f572aed8f78be4d0acaaffe45a Mon Sep 17 00:00:00 2001 From: Lukas Senionis Date: Fri, 26 Aug 2022 20:34:56 +0300 Subject: [PATCH] fix(utils): update wrapReactClass impl. and defaults for prop argument (#17) --- src/utils.ts | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 5794c03..0f6b5b7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -82,25 +82,14 @@ export function unpatch(obj: any, name: any): void { obj[name] = obj[name].__deckyOrig; } -export function wrapReactType(node: any, prop?: any) { - return node[prop || "type"] = {...node[prop || "type"]}; +export function wrapReactType(node: any, prop: any = 'type') { + return node[prop] = {...node[prop]}; } -export function wrapReactClass(node: any, prop?: any) { - const cls = node[prop || "type"]; +export function wrapReactClass(node: any, prop: any = 'type') { + const cls = node[prop]; const wrappedCls = class extends cls {}; - Object.getOwnPropertyNames(cls.prototype).forEach((prop: any) => { - try { - wrappedCls.prototype[prop] = cls.prototype[prop] - } catch (e) {} - }); - Object.getOwnPropertyNames(cls).forEach((prop: any) => { - try { - if (prop != "prototype") wrappedCls[prop] = cls[prop] - } catch (e) {} - }); - wrappedCls.prototype.__proto__ = cls.prototype.__proto__; - return node[prop || "type"] = wrappedCls; + return node[prop] = wrappedCls; } export function getReactInstance(o: HTMLElement | Element | Node) { @@ -142,4 +131,4 @@ export const findInTree = (parent: any, filter: findInTreeFilter, opts: findInTr export const findInReactTree = (node: any, filter: findInTreeFilter) => findInTree(node, filter, { // Specialised findInTree for React nodes walkable: [ 'props', 'children', 'child', 'sibling' ] -}); \ No newline at end of file +});