-
-
Notifications
You must be signed in to change notification settings - Fork 166
Description
1. Motivation
The current implementation of afterSetListeners
in Neo.core.Observable
is functional but inefficient for runtime updates. When the listeners_
config is modified, the hook removes all previously declared listeners and re-adds all the new ones. This "brute-force" approach can cause unnecessary overhead, especially in dynamic applications where listener configurations might change.
The goal is to make this process more intelligent and performant.
2. Goal
Refactor the afterSetListeners(value, oldValue)
method to perform a "diff" between the oldValue
and newValue
objects. The method should only apply the delta, rather than completely rebuilding the listener set.
This involves:
- Identifying and Removing Listeners: Iterate through
oldValue
. If a specific listener configuration does not exist innewValue
, it should be removed viaun()
. - Identifying and Adding Listeners: Iterate through
newValue
. If a listener does not exist inoldValue
, or if its definition has changed, it should be added viaon()
.
This ensures that listeners added imperatively via on()
remain unaffected and that only the necessary changes are made.
3. Acceptance Criteria
- The
afterSetListeners
method insrc/core/Observable.mjs
is updated to implement the diffing logic. - Runtime changes to the
listeners_
config correctly add, remove, and update event listeners without affecting listeners that were not part of the config. - All existing tests for
Observable
continue to pass. - (Optional but recommended) New unit tests are created to specifically verify the diffing logic in various scenarios (add, remove, update).