playcanvas / playcanvas/observer
.set path error
Open
@vkalpias is already working on this.
Since Sep 4, 2021.
bug
- Dominant language
- TypeScript
- Stars
- 26
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
There seems to be a bug with paths in the Observer.
The following code:
const o = new Observer({});
o.on('*:set', (path, value, oldValue) => {
console.log(`${path} = ${JSON.stringify(value)}`);
});
o.set('theParent.0.child', { x: 1, y: 2 });
Gives output:
theParent.0.child.child.x = 1
theParent.0.child.child.y = 2
theParent.0.child.child = {"x":1,"y":2}
Notice the third path should be theParent.0.child.
Looking at Observer's internal node tree suggests that all paths set here are incorrect. I believe the line should read:
_path: keys.slice(0, i).join('.')
Interestingly, if theParent.0.child is set to an atomic value before assigning an object then the resulting paths appear correct. However in this case '*:set' events don't propagate up the parent tree.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.