observe callback function second parameter 'oldValue' is always undefined
- Dominant language
- JavaScript
- Stars
- 30
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
The listener that observes for changes to property objects, contains the newValue but the oldValue is always undefined.
This documentation states that _"The listener will be called with the the new value as the first argument, and the old value as the second argument."_
So in the example below i expect when put(7) is called that in the callback function the newValue is 7 and the oldValue is 5 - however oldValue is undefined.
var validatingMemory = (declare([Memory, Validating]))({
Model: jsonSchema({
"type": "object",
"required": ["name"],
"properties": {
"prime": {
"type": 'boolean'
},
"number": {
"type": 'number',
"minimum": 1,
"maximum": 10
},
"name": {
"type": 'string'
},
"mappedTo": {
"type": 'string'
}
},
"additionalProperties": false
}),
idProperty: "name"
});
var data = [
{ name: 'one', number: 1, prime: false, mappedTo: 'E' },
{ name: 'two', number: 2, prime: true, mappedTo: 'D' },
{ name: 'three', number: 3, prime: true, mappedTo: 'C' },
{ name: 'four', number: 4, even: true, prime: false, mappedTo: 'B' },
{ name: 'five', number: 5, prime: true, mappedTo: 'A' }
];
//convert data to json string
var jsonString = JSON.stringify(data);
//convert string back to json object and insert back to Model
var obj = JSON.parse(jsonString);
validatingMemory.setData(obj);
var testingProperty = validatingMemory.getSync("five");
var testingPropertyObject = testingProperty.property('number');
testingPropertyObject.observe(
function (newValue, oldValue) {
console.log("old value: " + oldValue);
console.log("changed to new value: " + newValue);
},
{
onlyFutureUpdates: false
}
);
testingPropertyObject.put(7);
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by running the issue's reproduction with property('number').observe and put(7), then trace the observe callback and update path for the property object. Done means the callback receives 7 as newValue and 5 as oldValue instead of undefined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100