fix: improve perf by not returning implicitly

This commit is contained in:
PalmDevs 2025-06-17 19:53:58 +07:00
parent 255b4b4655
commit 77f8d62720
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
24 changed files with 87 additions and 35 deletions

View file

@ -35,7 +35,9 @@ export interface Cache {
} }
} }
const save = debounce(() => CacheStorage.set({}), 1000) const save = debounce(() => {
CacheStorage.set({})
}, 1000)
export function cacheAsset(asset: Asset, moduleId: Metro.ModuleID) { export function cacheAsset(asset: Asset, moduleId: Metro.ModuleID) {
// Merge directly into the cache, only debouncing actual writes // Merge directly into the cache, only debouncing actual writes

View file

@ -33,8 +33,7 @@ export const [Dispatcher, DispatcherModuleId] = lookupModule(
) as [DiscordModules.Flux.Dispatcher, Metro.ModuleID] ) as [DiscordModules.Flux.Dispatcher, Metro.ModuleID]
waitForModules(byProps<DiscordModules.Flux.Store>('_dispatchToken'), store => { waitForModules(byProps<DiscordModules.Flux.Store>('_dispatchToken'), store => {
const name = store.getName() _stores[store.getName()] = store
_stores[name] = store
}) })
const _stores: Record<string, any> = {} const _stores: Record<string, any> = {}

View file

@ -36,7 +36,9 @@ export interface Cache {
| undefined | undefined
} }
const save = debounce(() => CacheStorage.set({}), 1000) const save = debounce(() => {
CacheStorage.set({})
}, 1000)
export function cacheFilterResult( export function cacheFilterResult(
key: Filter['key'], key: Filter['key'],

View file

@ -304,7 +304,9 @@ export async function stopPlugin(plugin: InternalPlugin) {
// If the lifecycles don't finish in 5 seconds, a reload is probably required to unapply the changes // If the lifecycles don't finish in 5 seconds, a reload is probably required to unapply the changes
if (!finished) plugin.flags |= Flag.ReloadRequired if (!finished) plugin.flags |= Flag.ReloadRequired
}) })
.catch(e => handlePluginError(e, plugin)) .catch(e => {
handlePluginError(e, plugin)
})
else if ( else if (
!(plugin.status & (Status.PreInited | Status.Inited | Status.Started)) !(plugin.status & (Status.PreInited | Status.Inited | Status.Started))
) )

View file

@ -1,3 +1,5 @@
import { _emitter } from '@revenge-mod/plugins/_' import { _emitter } from '@revenge-mod/plugins/_'
_emitter.on('register', (plugin, options) => (plugin._s = options.storage)) _emitter.on('register', (plugin, options) => {
plugin._s = options.storage
})

View file

@ -6,7 +6,9 @@ export function debounce<F extends (...args: any[]) => any>(
return (...args: Parameters<F>) => return (...args: Parameters<F>) =>
new Promise(rs => { new Promise(rs => {
clearTimeout(timer) clearTimeout(timer)
timer = setTimeout(() => rs(func(...args)), timeout) timer = setTimeout(() => {
rs(func(...args))
}, timeout)
}) })
} }

View file

@ -67,7 +67,7 @@ export function interceptProperty(
delete proto[prop] delete proto[prop]
const desc = _intercepting.get(prop) const desc = _intercepting.get(prop)
if (desc) objectDefineProperty(proto, prop, desc) if (desc) objectDefineProperty(proto, prop, desc)
_intercepting.delete(prop) return _intercepting.delete(prop)
} }
} }

View file

@ -28,9 +28,15 @@ export function allSettled(
} }
export function sleep(ms: number): Promise<void> { export function sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms)) return new Promise(resolve => {
setTimeout(resolve, ms)
})
} }
export function sleepReject(ms: number, msg?: string): Promise<void> { export function sleepReject(ms: number, msg?: string): Promise<void> {
return new Promise((_, reject) => setTimeout(() => reject(msg), ms)) return new Promise((_, reject) => {
setTimeout(() => {
reject(msg)
}, ms)
})
} }

View file

@ -7,9 +7,8 @@ const { jsx: _jsx, jsxs: _jsxs, Fragment } = ReactJsxRuntime
const jsx = ((type, ...args) => const jsx = ((type, ...args) =>
_jsx(unproxy(type as object), ...args)) as typeof _jsx _jsx(unproxy(type as object), ...args)) as typeof _jsx
const jsxs = ((type, ...args) => { const jsxs = ((type, ...args) =>
return _jsxs(unproxy(type as object), ...args) _jsxs(unproxy(type as object), ...args)) as typeof _jsxs
}) as typeof _jsxs
function unproxy(type: object): ElementType { function unproxy(type: object): ElementType {
return (isProxified(type) return (isProxified(type)

View file

@ -4,10 +4,10 @@ import { interceptProperty } from '@revenge-mod/utils/objects'
// By doing this, we are assuming __METRO_GLOBAL_PREFIX__ is an empty string and globalThis.__d isn't already set. // By doing this, we are assuming __METRO_GLOBAL_PREFIX__ is an empty string and globalThis.__d isn't already set.
// But both should be true either way. // But both should be true either way.
const unintercept = interceptProperty( const unintercept = interceptProperty('__d', (_, mDefine) => {
'__d', unintercept()
(_, mDefine) => (unintercept(), patchMetroDefine(mDefine)), return patchMetroDefine(mDefine)
) })
import { import {
onModuleFirstRequired, onModuleFirstRequired,

View file

@ -16,7 +16,9 @@ const EvalJSSetting: SettingsItem = {
IconComponent: () => <TableRowAssetIcon name="FileIcon" />, IconComponent: () => <TableRowAssetIcon name="FileIcon" />,
title: () => 'Evaluate JavaScript', title: () => 'Evaluate JavaScript',
useDescription: () => 'Runs a JavaScript code snippet.', useDescription: () => 'Runs a JavaScript code snippet.',
onPress: () => AlertActionCreators.openAlert(AlertKey, <EvalJSAlert />), onPress: () => {
AlertActionCreators.openAlert(AlertKey, <EvalJSAlert />)
},
type: 'pressable', type: 'pressable',
} }
@ -99,7 +101,9 @@ function EvalJSAlert() {
<TextArea <TextArea
autoFocus autoFocus
label="Code" label="Code"
onChange={v => (code.current = v)} onChange={v => {
code.current = v
}}
placeholder="ReactNative.NativeModules.BundleUpdaterManager.reload()" placeholder="ReactNative.NativeModules.BundleUpdaterManager.reload()"
size="md" size="md"
/> />

View file

@ -14,7 +14,9 @@ const RDTAutoConnectSetting: SettingsItem = {
useValue: () => useValue: () =>
api.storage.use(s => s.devtools?.autoConnect !== undefined)!.devtools api.storage.use(s => s.devtools?.autoConnect !== undefined)!.devtools
.autoConnect, .autoConnect,
onValueChange: v => api.storage.set({ devtools: { autoConnect: v } }), onValueChange: v => {
api.storage.set({ devtools: { autoConnect: v } })
},
type: 'toggle', type: 'toggle',
} }

View file

@ -38,7 +38,10 @@ registerPlugin<{ storage: Storage }>(
api = api_ api = api_
if (isSettingsModulesLoaded()) require('./utils').register() if (isSettingsModulesLoaded()) require('./utils').register()
else onSettingsModulesLoaded(() => require('./utils').register()) else
onSettingsModulesLoaded(() => {
require('./utils').register()
})
if (api_.plugin.flags & PluginFlags.EnabledLate) if (api_.plugin.flags & PluginFlags.EnabledLate)
refreshSettingsOverviewScreen() refreshSettingsOverviewScreen()

View file

@ -46,7 +46,9 @@ export default function AssetBrowserSettingScreen() {
return ( return (
<Page spacing={16}> <Page spacing={16}>
<SearchInput <SearchInput
onChange={(v: string) => debouncedSetSearch(v)} onChange={(v: string) => {
debouncedSetSearch(v)
}}
size="md" size="md"
/> />
<FlashList.FlashList <FlashList.FlashList
@ -124,7 +126,9 @@ function AssetDisplay({
) )
} }
label={asset.name} label={asset.name}
onPress={() => openAssetDisplayAlert(asset, id, metadata)} onPress={() => {
openAssetDisplayAlert(asset, id, metadata)
}}
start={start} start={start}
subLabel={metadata subLabel={metadata
.filter(([, , , hiddenInText]) => !hiddenInText) .filter(([, , , hiddenInText]) => !hiddenInText)

View file

@ -69,7 +69,9 @@ export function RDTAddrSetting() {
}), }),
) )
} }
onChange={text => (RDTContext.addr = text)} onChange={text => {
RDTContext.addr = text
}}
returnKeyType="done" returnKeyType="done"
/> />
</View> </View>

View file

@ -111,7 +111,9 @@ export function InstalledPluginCard({
size="sm" size="sm"
variant="secondary" variant="secondary"
icon={SettingsIcon} icon={SettingsIcon}
onPress={() => navigatePluginSettings(plugin)} onPress={() => {
navigatePluginSettings(plugin)
}}
disabled={!enabled} disabled={!enabled}
/> />
</Pressable> </Pressable>

View file

@ -7,7 +7,9 @@ const ReloadSetting: SettingsItem = {
parent: Setting.Revenge, parent: Setting.Revenge,
IconComponent: () => <TableRowAssetIcon name="RetryIcon" />, IconComponent: () => <TableRowAssetIcon name="RetryIcon" />,
title: () => 'Reload App', title: () => 'Reload App',
onPress: () => BundleUpdaterManager.reload(), onPress: () => {
BundleUpdaterManager.reload()
},
type: 'pressable', type: 'pressable',
} }

View file

@ -8,7 +8,9 @@ const RevengeDiscordSetting: SettingsItem = {
parent: Setting.Revenge, parent: Setting.Revenge,
IconComponent: () => <TableRowAssetIcon name="Discord" />, IconComponent: () => <TableRowAssetIcon name="Discord" />,
title: () => 'Discord Server', title: () => 'Discord Server',
onPress: () => Linking.openURL(DiscordServerURL), onPress: () => {
Linking.openURL(DiscordServerURL)
},
type: 'pressable', type: 'pressable',
} }

View file

@ -10,7 +10,9 @@ const RevengeGitHubSetting: SettingsItem = {
<TableRowAssetIcon name="img_account_sync_github_white" /> <TableRowAssetIcon name="img_account_sync_github_white" />
), ),
title: () => 'GitHub', title: () => 'GitHub',
onPress: () => Linking.openURL(GitHubOrganizationURL), onPress: () => {
Linking.openURL(GitHubOrganizationURL)
},
type: 'pressable', type: 'pressable',
} }

View file

@ -31,8 +31,13 @@ let enabledCount = 0
for (const plugin of _plugins.values()) for (const plugin of _plugins.values())
if (plugin.flags & PluginFlags.Enabled) enabledCount++ if (plugin.flags & PluginFlags.Enabled) enabledCount++
_emitter.on('disabled', () => enabledCount--) _emitter.on('disabled', () => {
_emitter.on('enabled', () => enabledCount++) enabledCount--
})
_emitter.on('enabled', () => {
enabledCount++
})
export function useUpdateOnPluginStatesChange() { export function useUpdateOnPluginStatesChange() {
const reRender = useReRender() const reRender = useReRender()
@ -73,7 +78,9 @@ function showReloadRequiredAlertIfNeeded(plugin: InternalPlugin) {
<AlertActionButton <AlertActionButton
variant="destructive" variant="destructive"
text="Reload" text="Reload"
onPress={() => BundleUpdaterManager.reload()} onPress={() => {
BundleUpdaterManager.reload()
}}
/> />
<AlertActionButton variant="secondary" text="Not now" /> <AlertActionButton variant="secondary" text="Not now" />
</> </>

View file

@ -8,7 +8,9 @@ import { PluginFlags } from '@revenge-mod/plugins/constants'
import type { SettingsItem } from '@revenge-mod/discord/modules/settings' import type { SettingsItem } from '@revenge-mod/discord/modules/settings'
import type { FC } from 'react' import type { FC } from 'react'
onSettingsModulesLoaded(() => require('./register')) onSettingsModulesLoaded(() => {
require('./register')
})
registerPlugin( registerPlugin(
{ {

View file

@ -13,7 +13,9 @@ export default function RevengeCustomPageScreen({
const { render: PageComponent, options } = route.params const { render: PageComponent, options } = route.params
// biome-ignore lint/correctness/useExhaustiveDependencies: We only want to set options once // biome-ignore lint/correctness/useExhaustiveDependencies: We only want to set options once
useLayoutEffect(() => options && navigation.setOptions(options), []) useLayoutEffect(() => {
if (options) navigation.setOptions(options)
}, [])
return <PageComponent /> return <PageComponent />
} }

View file

@ -141,7 +141,9 @@ function Screen() {
<Stack direction="horizontal"> <Stack direction="horizontal">
<View style={styles.grow}> <View style={styles.grow}>
<SearchInput <SearchInput
onChange={(v: string) => debouncedSetSearch(v)} onChange={(v: string) => {
debouncedSetSearch(v)
}}
size="md" size="md"
/> />
</View> </View>

View file

@ -33,7 +33,9 @@ registerPlugin(
store.initialize() store.initialize()
unpatch() unpatch()
setTimeout(() => refreshSettingsOverviewScreen(true)) setTimeout(() => {
refreshSettingsOverviewScreen(true)
})
}, },
) )
} }