I'm having trouble getting the data returned properly. When you first load this page, it logs a blank {} for oldData, and "this" returns the element itself. When you click, it then logs the mouseEvent for the oldData, and the window element for "this".
I expect it should consistently log data from the schema. I'm not sure if the object should be blank when the update first fires, but it depends what "oldData" is at that point. I also expect "this" to consistently be a reference to the component function, not the window. What am I not considering here?
<html lang="en">
<head>
<script src="https://aframe.io/aframe/dist/aframe-master.min.js"></script>
<script>
AFRAME.registerComponent('my-component', {
multiple: false,
schema: {
mood: {
type: 'string',
default: 'happy'
}
},
init() {
window.addEventListener('click', this.update)
},
update(oldData) {
console.log("oldData: ", oldData);
console.log("this: ", this);
},
})
</script>
</head>
<body>
<a-scene>
<a-sky color="blue"></a-sky>
<a-box id="bluebox" color="green" position="-1 0 -3" my-component></a-box>
<a-light position="-3 4 2" type="spot" target="#bluebox"></a-light>
</a-scene>
</body>
</html>