()
| 72 | } |
| 73 | |
| 74 | const load = (): Promise<ComponentOrComponentOptions> => { |
| 75 | let thisRequest: Promise<ComponentOrComponentOptions> |
| 76 | return ( |
| 77 | pendingRequest || |
| 78 | (thisRequest = pendingRequest = |
| 79 | loader() |
| 80 | .catch((err) => { |
| 81 | err = err instanceof Error ? err : new Error(String(err)) |
| 82 | if (userOnError) { |
| 83 | return new Promise((resolve, reject) => { |
| 84 | const userRetry = () => resolve(retry()) |
| 85 | const userFail = () => reject(err) |
| 86 | userOnError(err, userRetry, userFail, retries + 1) |
| 87 | }) |
| 88 | } else { |
| 89 | throw err |
| 90 | } |
| 91 | }) |
| 92 | .then((comp: any) => { |
| 93 | if (thisRequest !== pendingRequest && pendingRequest) { |
| 94 | return pendingRequest |
| 95 | } |
| 96 | if (__DEV__ && !comp) { |
| 97 | warn( |
| 98 | `Async component loader resolved to undefined. ` + |
| 99 | `If you are using retry(), make sure to return its return value.` |
| 100 | ) |
| 101 | } |
| 102 | // interop module default |
| 103 | if ( |
| 104 | comp && |
| 105 | (comp.__esModule || comp[Symbol.toStringTag] === 'Module') |
| 106 | ) { |
| 107 | comp = comp.default |
| 108 | } |
| 109 | if (__DEV__ && comp && !isObject(comp) && !isFunction(comp)) { |
| 110 | throw new Error(`Invalid async component load result: ${comp}`) |
| 111 | } |
| 112 | return comp |
| 113 | })) |
| 114 | ) |
| 115 | } |
| 116 | |
| 117 | return () => { |
| 118 | const component = load() |
no test coverage detected
searching dependent graphs…