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) {
// 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]
waitForModules(byProps<DiscordModules.Flux.Store>('_dispatchToken'), store => {
const name = store.getName()
_stores[name] = store
_stores[store.getName()] = store
})
const _stores: Record<string, any> = {}

View file

@ -36,7 +36,9 @@ export interface Cache {
| undefined
}
const save = debounce(() => CacheStorage.set({}), 1000)
const save = debounce(() => {
CacheStorage.set({})
}, 1000)
export function cacheFilterResult(
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 (!finished) plugin.flags |= Flag.ReloadRequired
})
.catch(e => handlePluginError(e, plugin))
.catch(e => {
handlePluginError(e, plugin)
})
else if (
!(plugin.status & (Status.PreInited | Status.Inited | Status.Started))
)

View file

@ -1,3 +1,5 @@
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>) =>
new Promise(rs => {
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]
const desc = _intercepting.get(prop)
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> {
return new Promise(resolve => setTimeout(resolve, ms))
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
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) =>
_jsx(unproxy(type as object), ...args)) as typeof _jsx
const jsxs = ((type, ...args) => {
return _jsxs(unproxy(type as object), ...args)
}) as typeof _jsxs
const jsxs = ((type, ...args) =>
_jsxs(unproxy(type as object), ...args)) as typeof _jsxs
function unproxy(type: object): ElementType {
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.
// But both should be true either way.
const unintercept = interceptProperty(
'__d',
(_, mDefine) => (unintercept(), patchMetroDefine(mDefine)),
)
const unintercept = interceptProperty('__d', (_, mDefine) => {
unintercept()
return patchMetroDefine(mDefine)
})
import {
onModuleFirstRequired,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -13,7 +13,9 @@ export default function RevengeCustomPageScreen({
const { render: PageComponent, options } = route.params
// 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 />
}

View file

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

View file

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