Change how reflection works

This commit is contained in:
Jiiks 2018-03-08 10:59:51 +02:00
parent 43359d771c
commit fdfd961390
2 changed files with 22 additions and 2 deletions

View File

@ -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;

View File

@ -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);
}