(name, definition)
| 123 | * @param {object} definition - Component property and methods. |
| 124 | */ |
| 125 | export function registerSystem (name, definition) { |
| 126 | var i; |
| 127 | var NewSystem; |
| 128 | var proto = {}; |
| 129 | var scenes = utils.findAllScenes(document); |
| 130 | |
| 131 | // Format definition object to prototype object. |
| 132 | Object.keys(definition).forEach(function (key) { |
| 133 | proto[key] = { |
| 134 | value: definition[key], |
| 135 | writable: true |
| 136 | }; |
| 137 | }); |
| 138 | |
| 139 | if (systems[name]) { |
| 140 | throw new Error('The system `' + name + '` has been already registered. ' + |
| 141 | 'Check that you are not loading two versions of the same system ' + |
| 142 | 'or two different systems of the same name.'); |
| 143 | } |
| 144 | NewSystem = function (sceneEl) { System.call(this, sceneEl); }; |
| 145 | NewSystem.prototype = Object.create(System.prototype, proto); |
| 146 | NewSystem.prototype.name = name; |
| 147 | NewSystem.prototype.constructor = NewSystem; |
| 148 | NewSystem.prototype.schema = processSchema(NewSystem.prototype.schema); |
| 149 | systems[name] = NewSystem; |
| 150 | |
| 151 | // Initialize systems for existing scenes |
| 152 | if (ready.canInitializeElements) { |
| 153 | for (i = 0; i < scenes.length; i++) { scenes[i].initSystem(name); } |
| 154 | } |
| 155 | } |
no test coverage detected