Skip to main content
added 65 characters in body
Source Link
ngokevin
  • 13.3k
  • 5
  • 46
  • 88

You could rely on the event bubbling and listen on the scene, and store the entity in the event detail so you know where it came from:

// data-controller component
this.el.emit('dataready', {value: 2, el: this.el})
// Event will bubble to the scene.

// road component
this.el.sceneEl.addEventListener('dataready', function () { // ... });

Or you can pass a reference with the selector property type to which entity to want to listen to:

// road component
schema: {
    dataEl: {type: 'selector'},
    width: {type: 'number', default: 4},
    height: {type: 'number', default: 4}
},

init: function () {
  // ...
  this.data.dataEl.addEventListener('dataready', function () { // ... });
} 

// <a-entity road="dataEl: [data-controller]"></a-entity>

You could rely on the event bubbling and listen on the scene, and store the entity in the event detail so you know where it came from:

// data-controller component
this.el.emit('dataready', {value: 2, el: this.el})
// Event will bubble to the scene.

// road component
this.el.sceneEl.addEventListener('dataready', function () { // ... });

Or you can pass a reference with the selector property type to which entity to want to listen to:

// road component
schema: {
    dataEl: {type: 'selector'},
    width: {type: 'number', default: 4},
    height: {type: 'number', default: 4}
},

init: function () {
  // ...
  this.data.dataEl.addEventListener('dataready', function () { // ... });
}

You could rely on the event bubbling and listen on the scene, and store the entity in the event detail so you know where it came from:

// data-controller component
this.el.emit('dataready', {value: 2, el: this.el})
// Event will bubble to the scene.

// road component
this.el.sceneEl.addEventListener('dataready', function () { // ... });

Or you can pass a reference with the selector property type to which entity to want to listen to:

// road component
schema: {
    dataEl: {type: 'selector'},
    width: {type: 'number', default: 4},
    height: {type: 'number', default: 4}
},

init: function () {
  // ...
  this.data.dataEl.addEventListener('dataready', function () { // ... });
} 

// <a-entity road="dataEl: [data-controller]"></a-entity>
Source Link
ngokevin
  • 13.3k
  • 5
  • 46
  • 88

You could rely on the event bubbling and listen on the scene, and store the entity in the event detail so you know where it came from:

// data-controller component
this.el.emit('dataready', {value: 2, el: this.el})
// Event will bubble to the scene.

// road component
this.el.sceneEl.addEventListener('dataready', function () { // ... });

Or you can pass a reference with the selector property type to which entity to want to listen to:

// road component
schema: {
    dataEl: {type: 'selector'},
    width: {type: 'number', default: 4},
    height: {type: 'number', default: 4}
},

init: function () {
  // ...
  this.data.dataEl.addEventListener('dataready', function () { // ... });
}