Search all matching elements instead of just the first and don’t fail if a filter function is passed

This commit is contained in:
Samuel Elliott 2018-08-06 04:30:48 +01:00
parent 520366c4ac
commit 13437c56d4
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 16 additions and 5 deletions

View File

@ -233,12 +233,23 @@ export class ReactComponents {
return; return;
} }
const element = document.querySelector(important.selector); const elements = document.querySelectorAll(important.selector);
if (!element) return; if (!elements.length) return;
let component, reflect;
for (let element of elements) {
reflect = Reflection(element);
component = filter ? reflect.components.find(filter) : reflect.component;
if (component) break;
}
if (!component && filter) {
Logger.log('ReactComponents', ['Found elements matching the query selector but no components passed the filter']);
return;
}
DOM.observer.unsubscribe(observerSubscription); DOM.observer.unsubscribe(observerSubscription);
const reflect = Reflection(element);
const component = filter ? reflect.components.find(filter) : reflect.component;
if (!component) { if (!component) {
Logger.err('ReactComponents', [`FAILED TO GET IMPORTANT COMPONENT ${name} WITH REFLECTION FROM`, element]); Logger.err('ReactComponents', [`FAILED TO GET IMPORTANT COMPONENT ${name} WITH REFLECTION FROM`, element]);
return; return;
@ -250,7 +261,7 @@ export class ReactComponents {
this.push(component, undefined, important); this.push(component, undefined, important);
}; };
const observerSubscription = DOM.observer.subscribeToQuerySelector(callback, important.selector); const observerSubscription = DOM.observer.subscribeToQuerySelector(callback, important.selector, null, true);
setTimeout(callback, 0); setTimeout(callback, 0);
} }