Problem
Neo.apps and Neo.appsByName are lazily initialized in Neo.controller.Application#construct. Accessing them in Neo.worker.App (e.g., createNeoInstance) before any app is created can cause a crash if they are undefined.
onVisibilityChange and onOrientationChange currently iterate over all apps to find the matching instance or broadcast the event. Since these events are tied to a specific window, we can use a direct lookup for better performance and correctness.
Proposed Changes
- Initialize Global Maps: In
src/worker/App.mjs construct(), initialize Neo.apps and Neo.appsByName to {}.
- Optimize
onVisibilityChange: Replace the Object.values(Neo.apps) iteration with a direct lookup: Neo.apps[msg.data.windowId].
- Optimize
onOrientationChange: Replace the Object.values(Neo.apps) iteration with a direct lookup using the windowId from the event data.
Note on createNeoInstance:
The fallback logic let appName = Object.values(Neo.apps)[0]?.name is preserved but becomes safe due to the initialization in step 1.
Problem
Neo.appsandNeo.appsByNameare lazily initialized inNeo.controller.Application#construct. Accessing them inNeo.worker.App(e.g.,createNeoInstance) before any app is created can cause a crash if they areundefined.onVisibilityChangeandonOrientationChangecurrently iterate over all apps to find the matching instance or broadcast the event. Since these events are tied to a specific window, we can use a direct lookup for better performance and correctness.Proposed Changes
src/worker/App.mjsconstruct(), initializeNeo.appsandNeo.appsByNameto{}.onVisibilityChange: Replace theObject.values(Neo.apps)iteration with a direct lookup:Neo.apps[msg.data.windowId].onOrientationChange: Replace theObject.values(Neo.apps)iteration with a direct lookup using the windowId from the event data.Note on
createNeoInstance: The fallback logiclet appName = Object.values(Neo.apps)[0]?.nameis preserved but becomes safe due to the initialization in step 1.