From fdfd961390e0581401bbd75c4eecddbc01eeb5a7 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Thu, 8 Mar 2018 10:59:51 +0200 Subject: [PATCH] Change how reflection works --- client/src/ui/automanip.js | 4 +++- client/src/ui/reflection.js | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/client/src/ui/automanip.js b/client/src/ui/automanip.js index 1f2db70f..f0a71721 100644 --- a/client/src/ui/automanip.js +++ b/client/src/ui/automanip.js @@ -39,6 +39,7 @@ class TempApi { export default class { constructor() { + window.Reflection = Reflection; Events.on('server-switch', e => { try { this.appMount.setAttribute('guild-id', TempApi.currentGuildId); @@ -62,7 +63,8 @@ export default class { setIds() { for (let msg of document.querySelectorAll('.message')) { if (msg.hasAttribute('message-id')) continue; - const message = Reflection.findProp(msg, 'message'); + const r = Reflection(msg); + const message = r.prop('message'); if (!message) continue; const { id, author } = message; if (!id || !author) continue; diff --git a/client/src/ui/reflection.js b/client/src/ui/reflection.js index 9410f256..2f5249af 100644 --- a/client/src/ui/reflection.js +++ b/client/src/ui/reflection.js @@ -8,7 +8,7 @@ * LICENSE file in the root directory of this source tree. */ -export default class { +class Reflection { static reactInternalInstance(node) { if (!Object.keys(node) || !Object.keys(node).length) return null; const riiKey = Object.keys(node).find(k => k.startsWith('__reactInternalInstance')); @@ -54,3 +54,21 @@ export default class { return null; } } + +export default function (node) { + return new class Reflect { + constructor(node) { + if ('string' === typeof node) node = document.querySelector(node); + this.node = this.el = this.element = node; + } + get props() { + return 'not yet implemented'; + } + get reactInternalInstance() { + return Reflection.reactInternalInstance(this.node); + } + prop(propName) { + return Reflection.findProp(this.node, propName); + } + }(node); +}