fix(lib/modules/finders/wait): waitForModuleByImportedPath exports always being bad
This commit is contained in:
parent
831636f14c
commit
30c919a8a9
1 changed files with 11 additions and 15 deletions
|
|
@ -2,6 +2,7 @@ import { mInitialized } from '../metro/patches'
|
|||
import {
|
||||
onAnyModuleInitialized,
|
||||
onModuleFinishedImporting,
|
||||
onModuleInitialized,
|
||||
} from '../metro/subscriptions'
|
||||
import { getInitializedModuleExports } from '../metro/utils'
|
||||
import {
|
||||
|
|
@ -151,21 +152,16 @@ export function waitForModuleByImportedPath<T = any>(
|
|||
callback: WaitForModulesCallback<T>,
|
||||
options?: BaseWaitForModulesOptions,
|
||||
): WaitForModulesUnsubscribeFunction {
|
||||
const unsub = onModuleFinishedImporting(
|
||||
options?.all
|
||||
? (id, cmpPath) => {
|
||||
if (path === cmpPath) {
|
||||
unsub()
|
||||
callback(getInitializedModuleExports(id), id)
|
||||
}
|
||||
}
|
||||
: (id, cmpPath) => {
|
||||
if (mInitialized.has(id) && path === cmpPath) {
|
||||
unsub()
|
||||
callback(getInitializedModuleExports(id), id)
|
||||
}
|
||||
},
|
||||
)
|
||||
const unsub = onModuleFinishedImporting((id, cmpPath) => {
|
||||
if (path === cmpPath) {
|
||||
unsub()
|
||||
// Module is not fully initialized yet, so we need to wait for it
|
||||
onModuleInitialized(id, () => {
|
||||
if (!options?.all || mInitialized.has(id))
|
||||
callback(getInitializedModuleExports(id), id)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return unsub
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue