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

Method initComponent

src/core/a-entity.js:273–315  ·  view source on GitHub ↗

* Initialize component. * * @param {string} attrName - Attribute name associated to the component. * @param {object} data - Component data * @param {boolean} isDependency - True if the component is a dependency.

(attrName, data, isDependency)

Source from the content-addressed store, hash-verified

271 * @param {boolean} isDependency - True if the component is a dependency.
272 */
273 initComponent (attrName, data, isDependency) {
274 var component;
275 var componentId;
276 var componentInfo;
277 var componentName;
278 var isComponentDefined;
279
280 componentInfo = utils.split(attrName, MULTIPLE_COMPONENT_DELIMITER);
281 componentName = componentInfo[0];
282 componentId = componentInfo.length > 2
283 ? componentInfo.slice(1).join('__')
284 : componentInfo[1];
285
286 // Not a registered component.
287 if (!COMPONENTS[componentName]) { return; }
288
289 // Component is not a dependency and is undefined.
290 // If a component is a dependency, then it is okay to have no data.
291 isComponentDefined = checkComponentDefined(this, attrName) ||
292 data !== undefined;
293 if (!isComponentDefined && !isDependency) { return; }
294
295 // Component already initialized.
296 if (attrName in this.components) { return; }
297
298 // Initialize dependencies first
299 this.initComponentDependencies(componentName);
300
301 // Initialize component
302 component = new COMPONENTS[componentName].Component(this, data, componentId);
303 if (this.isPlaying) { component.play(); }
304
305 // Components are reflected in the DOM as attributes but the state is not shown
306 // hence we set the attribute to empty string.
307 // The flag justInitialized is for attributeChangedCallback to not overwrite
308 // the component with the empty string.
309 if (!this.hasAttribute(attrName)) {
310 component.justInitialized = true;
311 window.HTMLElement.prototype.setAttribute.call(this, attrName, '');
312 }
313
314 debug('Component initialized: %s', attrName);
315 }
316
317 /**
318 * Initialize dependencies of a component.

Callers 5

updateComponentMethod · 0.95
mixinUpdateMethod · 0.95
component.jsFile · 0.80
a-entity.test.jsFile · 0.80

Calls 3

checkComponentDefinedFunction · 0.85
playMethod · 0.45

Tested by

no test coverage detected