( type: Type<any> | AbstractType<any>, dependencyLoaderFn: () => Array<Promise<Type<unknown> | AbstractType<unknown>>>, metadataSetterFn: (...types: (Type<unknown> | AbstractType<unknown>)[]) => void, )
| 49 | * @param metadataSetterFn Function that forms a scope in which the `setClassMetadata` is invoked |
| 50 | */ |
| 51 | export function setClassMetadataAsync( |
| 52 | type: Type<any> | AbstractType<any>, |
| 53 | dependencyLoaderFn: () => Array<Promise<Type<unknown> | AbstractType<unknown>>>, |
| 54 | metadataSetterFn: (...types: (Type<unknown> | AbstractType<unknown>)[]) => void, |
| 55 | ): () => Promise<Array<Type<unknown> | AbstractType<unknown>>> { |
| 56 | const componentClass = type as any; // cast to `any`, so that we can monkey-patch it |
| 57 | componentClass[ASYNC_COMPONENT_METADATA_FN] = () => |
| 58 | Promise.all(dependencyLoaderFn()).then((dependencies) => { |
| 59 | metadataSetterFn(...dependencies); |
| 60 | // Metadata is now set, reset field value to indicate that this component |
| 61 | // can by used/compiled synchronously. |
| 62 | componentClass[ASYNC_COMPONENT_METADATA_FN] = ASYNC_METADATA_LOADED; |
| 63 | |
| 64 | return dependencies; |
| 65 | }); |
| 66 | return componentClass[ASYNC_COMPONENT_METADATA_FN]; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Adds decorator, constructor, and property metadata to a given type via static metadata fields |
no test coverage detected