Created
April 19, 2017 20:20
-
-
Save caseyyee/5f88b4b54b777d500b7ed552696d3ad5 to your computer and use it in GitHub Desktop.
A-Frame component - which-controller-present
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// by: @machenmusik | |
AFRAME.registerComponent('which-controller-present', { | |
init: function () { | |
this.el.addEventListener('componentinitialized', (function (evt) { | |
if (evt.detail.name !== 'tracked-controls') { return; } | |
// Determine which, if any, higher level controller component says controllerPresent. | |
// WARNING! If a dummy tracked-controls instance is already present, | |
// then componentinitialized may not fire for true injection! | |
Object.keys(this.el.components).forEach((name) => { | |
const component = this.el.components[name]; | |
if (component.controllerPresent) { | |
// Log name, component data, and tracked-controls data. | |
console.log(name + ' ' + JSON.stringify(component.data) + ' => ' + JSON.stringify(event.detail.data)); | |
// Emit controllerpresent event. | |
this.el.emit('controllerpresent', {name: name, component: component}); | |
} | |
}); | |
}).bind(this)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment