Motivation
The previous implementation of Neo.grid.ScrollManager used a manual setTimeout with a clearTimeout call inside the onBodyScroll method to manage the gridBody.isScrolling flag. This approach, while functional, has several drawbacks:
- Manual Implementation: It bypasses the framework's built-in
delayable feature, which is designed for exactly this purpose.
- Inconsistency: The logic was only applied to vertical scrolling (
onBodyScroll), not horizontal scrolling (onContainerScroll).
- Potential for Bugs: Manual timer management can be more prone to edge cases and race conditions compared to a declarative, framework-level solution.
The goal of this refactoring was to improve scroll performance, increase code clarity, and ensure consistent behavior across all scroll directions by leveraging the delayable system.
Changes Implemented
The ScrollManager was refactored with the following changes:
Throttled Scroll Handlers:
- Both
onBodyScroll (vertical) and onContainerScroll (horizontal) are now configured as throttled delayable methods, limited to firing once every 16ms. This aligns event processing with a 60fps browser refresh rate, preventing scroll jank.
Debounced Scroll End Handler:
- A new
onBodyScrollEnd method was created. Its sole responsibility is to set gridBody.isScrolling = false.
- This new method is configured as a
delayable with {type: 'buffer', timer: 150}. This acts as a trailing-edge debounce, ensuring it only executes once, 150ms after the user has completely stopped scrolling.
Simplified Logic:
- The manual
setTimeout, clearTimeout, and the scrollTimeoutId property were removed from the class.
- Both
onBodyScroll and onContainerScroll now immediately set body.isScrolling = true and then call me.onBodyScrollEnd(), delegating the "scroll end" detection to the debounced method.
Benefits
This refactoring provides several key benefits:
- Improved Performance: Throttling scroll events reduces the processing overhead during rapid scrolling, leading to a smoother user experience.
- Enhanced Code Quality: The code is now more declarative and easier to understand by using the framework's intended features (
delayable) instead of manual timer logic.
- Consistency: Both vertical and horizontal scrolling now share the same robust mechanism for managing the
isScrolling state.
- Reduced Complexity: The removal of manual timer management simplifies the
ScrollManager's implementation.
Motivation
The previous implementation of
Neo.grid.ScrollManagerused a manualsetTimeoutwith aclearTimeoutcall inside theonBodyScrollmethod to manage thegridBody.isScrollingflag. This approach, while functional, has several drawbacks:delayablefeature, which is designed for exactly this purpose.onBodyScroll), not horizontal scrolling (onContainerScroll).The goal of this refactoring was to improve scroll performance, increase code clarity, and ensure consistent behavior across all scroll directions by leveraging the
delayablesystem.Changes Implemented
The
ScrollManagerwas refactored with the following changes:Throttled Scroll Handlers:
onBodyScroll(vertical) andonContainerScroll(horizontal) are now configured as throttleddelayablemethods, limited to firing once every 16ms. This aligns event processing with a 60fps browser refresh rate, preventing scroll jank.Debounced Scroll End Handler:
onBodyScrollEndmethod was created. Its sole responsibility is to setgridBody.isScrolling = false.delayablewith{type: 'buffer', timer: 150}. This acts as a trailing-edge debounce, ensuring it only executes once, 150ms after the user has completely stopped scrolling.Simplified Logic:
setTimeout,clearTimeout, and thescrollTimeoutIdproperty were removed from the class.onBodyScrollandonContainerScrollnow immediately setbody.isScrolling = trueand then callme.onBodyScrollEnd(), delegating the "scroll end" detection to the debounced method.Benefits
This refactoring provides several key benefits:
delayable) instead of manual timer logic.isScrollingstate.ScrollManager's implementation.