1. Summary
This ticket covers the foundational work on Neo.functional.component.Base to enable the hook system (useConfig, useEvent, etc.) for beginner-mode functional components. The key challenge was to allow external hook functions to manage state on a component instance without exposing that state through the public API.
2. Rationale
The initial implementation of functional.component.Base was a minimal class with a createVdom method driven by an Effect. To support hooks like React's useState, we needed a mechanism to:
- Associate state (like
Config instances) with a specific component instance.
- Track the order of hook calls within a single
createVdom execution.
- Provide a way for external hook functions to access this internal state securely.
Using protected properties (e.g., _hooks) was considered but deemed insufficient for true encapsulation. The chosen solution provides a robust, framework-private way to manage hook state.
3. Scope & Implementation Plan
Introduce Symbols for State:
- Create two
Symbol.for() symbols: hookIndexSymbol and hooksSymbol.
- These symbols act as unique keys for properties on the component instance, making them accessible to any module that knows the symbol, but keeping them off the public API.
Initialize State in FunctionalBase:
- In the
construct() method of functional.component.Base, use Object.defineProperties to add the symbol-keyed properties ([hookIndexSymbol] and [hooksSymbol]) to the component instance.
- These properties are configured to be non-enumerable (
enumerable: false) to further hide them from standard object iteration.
- The
hookIndex is reset to 0 at the beginning of every vdomEffect execution, ensuring a clean slate for each render.
Component Registration:
- Implement the
afterSetId() and destroy() methods to correctly register and unregister the functional component instance with Neo.manager.Component. This makes functional components discoverable via Neo.getComponent(), integrating them fully into the framework's component model.
Link Effect to Component:
- Modify the
vdomEffect creation to pass the component's ID (this.id) to the Effect constructor. This allows the useConfig hook to retrieve the currently rendering component instance by getting the active effect from EffectManager and looking up the component by its ID.
4. Definition of Done
functional.component.Base is updated to use Symbol.for() to manage internal hook state.
- The component correctly registers and unregisters itself with
ComponentManager.
- The
vdomEffect is correctly associated with the component's ID.
- The implementation provides the necessary foundation for the
useConfig hook to function correctly.
1. Summary
This ticket covers the foundational work on
Neo.functional.component.Baseto enable the hook system (useConfig,useEvent, etc.) for beginner-mode functional components. The key challenge was to allow external hook functions to manage state on a component instance without exposing that state through the public API.2. Rationale
The initial implementation of
functional.component.Basewas a minimal class with acreateVdommethod driven by anEffect. To support hooks like React'suseState, we needed a mechanism to:Configinstances) with a specific component instance.createVdomexecution.Using protected properties (e.g.,
_hooks) was considered but deemed insufficient for true encapsulation. The chosen solution provides a robust, framework-private way to manage hook state.3. Scope & Implementation Plan
Introduce Symbols for State:
Symbol.for()symbols:hookIndexSymbolandhooksSymbol.Initialize State in
FunctionalBase:construct()method offunctional.component.Base, useObject.definePropertiesto add the symbol-keyed properties ([hookIndexSymbol]and[hooksSymbol]) to the component instance.enumerable: false) to further hide them from standard object iteration.hookIndexis reset to0at the beginning of everyvdomEffectexecution, ensuring a clean slate for each render.Component Registration:
afterSetId()anddestroy()methods to correctly register and unregister the functional component instance withNeo.manager.Component. This makes functional components discoverable viaNeo.getComponent(), integrating them fully into the framework's component model.Link Effect to Component:
vdomEffectcreation to pass the component's ID (this.id) to theEffectconstructor. This allows theuseConfighook to retrieve the currently rendering component instance by getting the active effect fromEffectManagerand looking up the component by its ID.4. Definition of Done
functional.component.Baseis updated to useSymbol.for()to manage internal hook state.ComponentManager.vdomEffectis correctly associated with the component's ID.useConfighook to function correctly.