revenge-bundle-next/lib/modules/src/metro/subscriptions/_internal.ts

30 lines
1.2 KiB
TypeScript

import { _mInitingId } from '../_internal'
import type { ModuleInitializedCallback, ModuleRequiredCallback, ModuleWithImportedPathInitializedCallback } from '.'
import type { Metro } from '../../../types'
export const _reqAll = new Set<ModuleRequiredCallback>()
export const _reqSpecific = new Map<Metro.ModuleID, Set<ModuleRequiredCallback>>()
export const _initAll = new Set<ModuleInitializedCallback>()
export const _initSpecific = new Map<Metro.ModuleID, Set<ModuleInitializedCallback>>()
export const _importedPath = new Set<ModuleWithImportedPathInitializedCallback>()
export function _executeRequiredSubscription(id: Metro.ModuleID) {
for (const cb of _reqAll) cb(id)
if (_reqSpecific.has(id)) {
for (const cb of _reqSpecific.get(id)!) cb(id)
_reqSpecific.delete(id)
}
}
export function _executeInitializedSubscription(id: Metro.ModuleID, exports: Metro.ModuleExports) {
for (const cb of _initAll) cb(id, exports)
if (_initSpecific.has(id)) {
for (const cb of _initSpecific.get(id)!) cb(id, exports)
_initSpecific.delete(id)
}
}
export function _executeImportedPathSubscription(id: Metro.ModuleID, path: string) {
for (const cb of _importedPath) cb(id, path)
}