Skip to content

Commit

Permalink
fix primitive mapping to a single-prop component
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed Nov 10, 2016
1 parent c62c1c2 commit 1e67506
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/extras/primitives/primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ module.exports.registerPrimitive = function registerPrimitive (name, definition)
mapping = this.mappings[attr.name];
if (mapping) {
path = utils.entity.getComponentPropertyPath(mapping);
initialComponents[path[0]][path[1]] = attr.value;
if (path.constructor === Array) {
initialComponents[path[0]][path[1]] = attr.value;
} else {
initialComponents[path] = attr.value;
}
continue;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/extras/primitives/primitives.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,15 @@ suite('registerPrimitive (using innerHTML)', function () {
helpers.mixinFactory('foo', {material: 'color: red'}, sceneEl);
});
});

test('handles mapping to a single-property component', function (done) {
primitiveFactory({
mappings: {
viz: 'visible'
}
}, 'viz="false"', function postCreation (el) {
assert.equal(el.getAttribute('visible'), false);
done();
});
});
});

0 comments on commit 1e67506

Please sign in to comment.