refactor(PasteService): optimize handler registration logic (#6223)

- Updated registerHandler to only log and update the handler if it changes, reducing unnecessary operations.
- Removed logging from unregisterHandler for cleaner code.
This commit is contained in:
beyondkmp 2025-05-20 19:12:45 +08:00 committed by GitHub
parent 74fbd37a20
commit adf13979ca

View File

@ -157,8 +157,10 @@ export const init = () => {
export const registerHandler = (component: ComponentType, handler: PasteHandler) => {
if (!component) return
handlers[component] = handler
Logger.info(`[PasteService] Handler registered for ${component}`)
// Only log and update if the handler actually changes
if (!handlers[component] || handlers[component] !== handler) {
handlers[component] = handler
}
}
/**
@ -168,7 +170,6 @@ export const unregisterHandler = (component: ComponentType) => {
if (!component || !handlers[component]) return
delete handlers[component]
Logger.info(`[PasteService] Handler unregistered for ${component}`)
}
/**