Skip to content

Commit

Permalink
Add optional support for id and class in createEntity definition, mak…
Browse files Browse the repository at this point in the history
…e element optional, default to a-entity (#712)
  • Loading branch information
vincentfretin authored May 22, 2024
1 parent ddd1895 commit 08f754b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,19 @@ export function getComponentClipboardRepresentation(entity, componentName) {

/**
* Helper function to add a new entity with a list of components
* @param {object} definition Entity definition to add:
* {element: 'a-entity', components: {geometry: 'primitive:box'}}
* @param {object} definition Entity definition to add, only components is required:
* {element: 'a-entity', id: "hbiuSdYL2", class: "box", components: {geometry: 'primitive:box'}}
* @return {Element} Entity created
*/
export function createEntity(definition, cb) {
const entity = document.createElement(definition.element);
const entity = document.createElement(definition.element || 'a-entity');
if (definition.id) {
entity.id = definition.id;
}

if (definition.class) {
entity.setAttribute('class', definition.class);
}

// load default attributes
for (let attr in definition.components) {
Expand Down

0 comments on commit 08f754b

Please sign in to comment.