Listener has no knowledge of what property it is registered for
- Dominant language
- JavaScript
- Stars
- 30
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
The listener that is passed to observe(listener, options) is a function that is provided two values, 'newvalue' and 'oldvalue when the property it was registered for in the model was changed. However once inside the listener function, there is no way to know what property these values correspond to.
For example say you are trying to set up all your observers dynamically like this in a for loop
widget.observeHandles[property] = widget.propertyObjects[property].observe(
function (newValue, oldValue) {
console.log(property + " old value: " + oldValue);
console.log(property + " new value: " + newValue);
that.properties[property] = newValue;
that.propertyFunctions[property](newValue);
},
{
onlyFutureUpdates: onlyFutureUpdatesFlag
}
);
Once inside the function there is no knowledge of the property change which activated this function call, therefore you cannot run any code that depends on the name of that property.
Can this be added as a third parameter to the listener - like **function(newValue, oldValue, property)**?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the observe(listener, options) entry point and trace where newValue and oldValue are passed to the listener. Check how the registered property is retained and review existing observer coverage before deciding how the third argument should be exposed. Done means listeners can receive the property name without breaking existing two-argument listeners.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100