Merge pull request #289 from toolstik/feature/modules-deep-scan

Allow updates and scenes to be included from nested imported modules
This commit is contained in:
Aleksandr Bukhalo 2021-08-05 12:13:18 +03:00 committed by GitHub
commit 2195d6b9bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,12 +26,28 @@ export class BaseExplorerService {
modules: Module[], modules: Module[],
callback: (instance: InstanceWrapper, moduleRef: Module) => T | T[], callback: (instance: InstanceWrapper, moduleRef: Module) => T | T[],
): T[] { ): T[] {
const invokeMap = () => { const visitedModules = new Set<Module>();
return modules.map((moduleRef) => {
const unwrap = (moduleRef: Module) => {
// protection from circular recursion
if (visitedModules.has(moduleRef)) {
return [];
} else {
visitedModules.add(moduleRef);
}
const providers = [...moduleRef.providers.values()]; const providers = [...moduleRef.providers.values()];
return providers.map((wrapper) => callback(wrapper, moduleRef)); const defined = providers.map((wrapper) => callback(wrapper, moduleRef));
});
const imported: (T | T[])[] = moduleRef.imports?.size
? [...moduleRef.imports.values()].reduce((prev, cur) => {
return [...prev, ...unwrap(cur)];
}, [])
: [];
return [...defined, ...imported];
}; };
return flattenDeep(invokeMap()).filter(identity);
return flattenDeep(modules.map(unwrap)).filter(identity);
} }
} }