Description:
Currently, DOM event handling logic, including the domListeners_ config and related methods (afterSetDomListeners, addDomListeners, removeDomListeners), resides within src/component/Base.mjs.
To enable consistent DOM event support for both class-based components (src/component/Base.mjs) and functional components (src/functional/component/Base.mjs), and to improve code organization and reusability, this ticket proposes extracting this logic into a new mixin: src/mixin/DomEvents.mjs.
Proposed Changes:
Create src/mixin/DomEvents.mjs:
- Define the
domListeners_ config.
- Move
afterSetDomListeners, addDomListeners, and removeDomListeners methods to this mixin.
- Add
initDomEvents() and removeDomEvents() methods to encapsulate the mounting and unmounting of DOM listeners, respectively. These methods will be called from the component's lifecycle hooks.
Refactor src/component/Base.mjs:
- Remove the
domListeners_ config and the methods moved to DomEvents.mjs.
- Add
Neo.mixin.DomEvents to its mixins array.
- Call
this.initDomEvents() within its afterSetMounted() method.
- Call
this.removeDomEvents() within its destroy() method.
Update src/functional/component/Base.mjs:
- Add
Neo.mixin.DomEvents to its mixins array.
- Implement (or modify existing)
afterSetMounted() and destroy() methods to call this.initDomEvents() and this.removeDomEvents(), respectively.
This refactoring will ensure that both component types benefit from a centralized and reusable DOM event management system, aligning with the framework's pattern of using mixins for shared functionality.
Description: Currently, DOM event handling logic, including the
domListeners_config and related methods (afterSetDomListeners,addDomListeners,removeDomListeners), resides withinsrc/component/Base.mjs.To enable consistent DOM event support for both class-based components (
src/component/Base.mjs) and functional components (src/functional/component/Base.mjs), and to improve code organization and reusability, this ticket proposes extracting this logic into a new mixin:src/mixin/DomEvents.mjs.Proposed Changes:
Create
src/mixin/DomEvents.mjs:domListeners_config.afterSetDomListeners,addDomListeners, andremoveDomListenersmethods to this mixin.initDomEvents()andremoveDomEvents()methods to encapsulate the mounting and unmounting of DOM listeners, respectively. These methods will be called from the component's lifecycle hooks.Refactor
src/component/Base.mjs:domListeners_config and the methods moved toDomEvents.mjs.Neo.mixin.DomEventsto itsmixinsarray.this.initDomEvents()within itsafterSetMounted()method.this.removeDomEvents()within itsdestroy()method.Update
src/functional/component/Base.mjs:Neo.mixin.DomEventsto itsmixinsarray.afterSetMounted()anddestroy()methods to callthis.initDomEvents()andthis.removeDomEvents(), respectively.This refactoring will ensure that both component types benefit from a centralized and reusable DOM event management system, aligning with the framework's pattern of using mixins for shared functionality.