(name, definition)
| 609 | * @returns {object} Component. |
| 610 | */ |
| 611 | export 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 = |
no test coverage detected