Skip to content

Commit 8ba5efb

Browse files
dmarcosngokevin
authored andcommitted
When updating component attrValue has to be used instead of component.data (aframevr#2184)
1 parent a5af84b commit 8ba5efb

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

‎src/core/a-entity.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,10 @@ var proto = Object.create(ANode.prototype, {
686686
function componentUpdate (el, componentName, propValue) {
687687
var component = el.components[componentName];
688688
if (component && typeof propValue === 'object') {
689-
// Extend existing component data.
689+
// Extend existing component attribute value.
690690
el.updateComponent(
691691
componentName,
692-
utils.extendDeep(utils.extendDeep({}, component.data), propValue));
692+
utils.extendDeep(utils.extendDeep({}, component.attrValue), propValue));
693693
} else {
694694
el.updateComponent(componentName, propValue);
695695
}

‎src/utils/coordinates.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ function parse (value, defaultVec) {
1717
var vec = {};
1818

1919
if (value && typeof value === 'object') {
20-
return vecParseFloat(value);
20+
return vecParseFloat({
21+
x: value.x || defaultVec && defaultVec.x,
22+
y: value.y || defaultVec && defaultVec.y,
23+
z: value.z || defaultVec && defaultVec.z,
24+
w: value.w || defaultVec && defaultVec.w
25+
});
2126
}
2227

2328
if (typeof value !== 'string' || value === null) {

‎tests/core/a-entity.test.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,29 @@ suite('a-entity', function () {
363363
el.setAttribute('test', 'asym', 1);
364364
el.setAttribute('test', 'other', 2);
365365
});
366+
367+
test('the attribute cache only stores the modified properties', function () {
368+
var el = this.el;
369+
el.setAttribute('geometry', {primitive: 'box'});
370+
assert.deepEqual(el.components.geometry.attrValue, {primitive: 'box'});
371+
el.setAttribute('geometry', {primitive: 'sphere', radius: 10});
372+
assert.deepEqual(el.components.geometry.attrValue, {primitive: 'sphere', radius: 10});
373+
});
374+
375+
test('when changing schema only the modified properties are cached', function () {
376+
var el = this.el;
377+
var geometry;
378+
el.setAttribute('geometry', {primitive: 'box'});
379+
assert.deepEqual(el.components.geometry.attrValue, {primitive: 'box'});
380+
el.setAttribute('geometry', {primitive: 'sphere', radius: 10});
381+
assert.deepEqual(el.components.geometry.attrValue, {primitive: 'sphere', radius: 10});
382+
geometry = el.getAttribute('geometry');
383+
assert.equal(geometry.primitive, 'sphere');
384+
assert.equal(geometry.radius, 10);
385+
assert.notOk(geometry.depth);
386+
assert.notOk(geometry.height);
387+
assert.notOk(geometry.width);
388+
});
366389
});
367390

368391
suite('flushToDOM', function () {

‎tests/utils/coordinates.test.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ suite('utils.coordinates', function () {
1818
coordinates.parse('1 2.5 -3'), {x: 1, y: 2.5, z: -3});
1919
});
2020

21+
test('applies defaults to the missing values', function () {
22+
assert.deepEqual(
23+
coordinates.parse({x: 1}, {x: 0, y: 0, z: 0}), {x: 1, y: 0, z: 0});
24+
});
25+
2126
test('parses null', function () {
2227
assert.equal(coordinates.parse(null), null);
2328
});

0 commit comments

Comments
 (0)