The onWorkerMessage method in src/worker/Manager.mjs has accumulated redundant logic for handling message replies, specifically the promise registration and sendMessage sequence. This has been exacerbated by the recent addition of updateVdom handling and the zero-delta optimization.
Goal:
Refactor onWorkerMessage to eliminate code duplication by extracting the common reply/promise logic into a reusable helper method.
Plan:
- Identify the common pattern:
- Check for deltas.
- If empty -> Immediate reply.
- If present -> Register promise -> Fire event -> Send reply on promise resolution.
- Create a helper method
handleDomUpdate({ data, eventName }).
data: The message payload.
eventName: The event to fire (e.g., 'updateVdom', 'automount').
- Update
onWorkerMessage to use this helper for both action === 'updateVdom' and the action === 'reply' (VDOM) path.
This will reduce file size and improve maintainability.
The
onWorkerMessagemethod insrc/worker/Manager.mjshas accumulated redundant logic for handling message replies, specifically the promise registration andsendMessagesequence. This has been exacerbated by the recent addition ofupdateVdomhandling and the zero-delta optimization.Goal: Refactor
onWorkerMessageto eliminate code duplication by extracting the common reply/promise logic into a reusable helper method.Plan:
handleDomUpdate({ data, eventName }).data: The message payload.eventName: The event to fire (e.g.,'updateVdom','automount').onWorkerMessageto use this helper for bothaction === 'updateVdom'and theaction === 'reply'(VDOM) path.This will reduce file size and improve maintainability.