Add filtering all components to ReactComponents

This commit is contained in:
Samuel Elliott 2018-04-27 15:52:43 +01:00
parent 1354b884b4
commit 17575fc6a1
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 8 additions and 7 deletions

View File

@ -210,7 +210,7 @@ export class ReactComponents {
return c;
}
static async getComponent(name, important) {
static async getComponent(name, important, filter) {
const have = this.components.find(c => c.id === name);
if (have) return have;
if (important) {
@ -223,24 +223,25 @@ export class ReactComponents {
const select = document.querySelector(important.selector);
if (!select) return;
const reflect = Reflection(select);
if (!reflect.component) {
const component = filter ? reflect.components.find(filter) || reflect.component : reflect.component;
if (!component) {
clearInterval(importantInterval);
Logger.error('ReactComponents', [`FAILED TO GET IMPORTANT COMPONENT ${name} WITH REFLECTION FROM`, select]);
return;
}
if (!reflect.component.displayName) reflect.component.displayName = name;
if (!component.displayName) component.displayName = name;
Logger.info('ReactComponents', [`Found important component ${name} with reflection`, reflect]);
this.push(reflect.component);
this.push(component);
clearInterval(importantInterval);
}, 50);
}
const listener = this.listeners.find(l => l.id === name);
if (!listener) this.listeners.push({
let listener = this.listeners.find(l => l.id === name);
if (!listener) this.listeners.push(listener = {
id: name,
listeners: []
});
return new Promise(resolve => {
this.listeners.find(l => l.id === name).listeners.push(resolve);
listener.listeners.push(resolve);
});
}