MCPcopy
hub / github.com/aframevr/aframe / registerComponent

Function registerComponent

src/core/component.js:611–704  ·  view source on GitHub ↗
(name, definition)

Source from the content-addressed store, hash-verified

609 * @returns {object} Component.
610 */
611export function registerComponent (name, definition) {
612 var NewComponent;
613 var proto = {};
614 var schema;
615 var schemaIsSingleProp;
616
617 // Warning if component is statically registered after the scene.
618 if (document.currentScript && document.currentScript !== aframeScript) {
619 scenes.forEach(function checkPosition (sceneEl) {
620 // Okay to register component after the scene at runtime.
621 if (sceneEl.hasLoaded) { return; }
622
623 // Check that component is declared before the scene.
624 if (document.currentScript.compareDocumentPosition(sceneEl) ===
625 Node.DOCUMENT_POSITION_FOLLOWING) { return; }
626
627 warn('The component `' + name + '` was registered in a <script> tag after the scene. ' +
628 'Component <script> tags in an HTML file should be declared *before* the scene ' +
629 'such that the component is available to entities during scene initialization.');
630
631 // For testing.
632 if (window.debug) { registrationOrderWarnings[name] = true; }
633 });
634 }
635
636 if (upperCaseRegExp.test(name) === true) {
637 warn('The component name `' + name + '` contains uppercase characters, but ' +
638 'HTML will ignore the capitalization of attribute names. ' +
639 'Change the name to be lowercase: `' + name.toLowerCase() + '`');
640 }
641
642 if (name.indexOf('__') !== -1) {
643 throw new Error('The component name `' + name + '` is not allowed. ' +
644 'The sequence __ (double underscore) is reserved to specify an id' +
645 ' for multiple components of the same type');
646 }
647
648 // Format definition object to prototype object.
649 Object.keys(definition).forEach(function (key) {
650 proto[key] = {
651 value: definition[key],
652 writable: true
653 };
654 });
655
656 if (components[name]) {
657 throw new Error('The component `' + name + '` has been already registered. ' +
658 'Check that you are not loading two versions of the same component ' +
659 'or two different components of the same name.');
660 }
661
662 NewComponent = function (el, attr, id) {
663 Component.call(this, el, attr, id);
664 };
665
666 NewComponent.prototype = Object.create(Component.prototype, proto);
667 NewComponent.prototype.name = name;
668 NewComponent.prototype.isPositionRotationScale =

Callers 15

line.jsFile · 0.90
visible.jsFile · 0.90
laser-controls.jsFile · 0.90
raycaster.jsFile · 0.90
anchored.jsFile · 0.90
wasd-controls.jsFile · 0.90
material.jsFile · 0.90
geometry.jsFile · 0.90

Calls 5

wrapPlayFunction · 0.85
wrapPauseFunction · 0.85
isObjectFunction · 0.85
parsePropertyFunction · 0.85
emitMethod · 0.80

Tested by

no test coverage detected