* Creates the memoized loader function in its own lexical scope so that the * prefetch callback does not share a closure context with `injector`.
( loader: () => Promise<InjectAsyncLoaderResult<T>>, )
| 82 | * prefetch callback does not share a closure context with `injector`. |
| 83 | */ |
| 84 | function createLoader<T>( |
| 85 | loader: () => Promise<InjectAsyncLoaderResult<T>>, |
| 86 | ): () => Promise<InjectAsyncLoaderResult<T>> { |
| 87 | let loadedPromise: Promise<InjectAsyncLoaderResult<T>> | null = null; |
| 88 | return () => { |
| 89 | if (!loadedPromise) { |
| 90 | loadedPromise = loader(); |
| 91 | } |
| 92 | return loadedPromise; |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Interface for `options` argument used within `injectAsync` call. |