Skip to content

Commit

Permalink
Accept mixin ids separated with spaces, tabs, and new lines (#2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirox authored and dmarcos committed Jan 18, 2017
1 parent 803b839 commit 1b9bea1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/a-node.js
Expand Up @@ -129,8 +129,8 @@ module.exports = registerElement('a-node', {

updateMixins: {
value: function (newMixins, oldMixins) {
var newMixinsIds = newMixins ? newMixins.split(' ') : [];
var oldMixinsIds = oldMixins ? oldMixins.split(' ') : [];
var newMixinsIds = newMixins ? newMixins.trim().split(/\s+/) : [];
var oldMixinsIds = oldMixins ? oldMixins.trim().split(/\s+/) : [];
// To determine what listeners will be removed
var diff = oldMixinsIds.filter(function (i) { return newMixinsIds.indexOf(i) < 0; });
this.mixinEls = [];
Expand Down
13 changes: 13 additions & 0 deletions tests/core/a-entity.test.js
Expand Up @@ -1046,6 +1046,19 @@ suite('a-entity', function () {
assert.equal(el.getAttribute('sound__2').autoplay, true);
});

test('applies mixin ids separated with spaces, tabs, and new lines', function () {
var el = this.el;
mixinFactory('material', {material: 'shader: flat'});
mixinFactory('position', {position: '1 2 3'});
mixinFactory('rotation', {rotation: '10 20 30'});
el.setAttribute('mixin', ' material\t\nposition \t rotation\n ');
el.setAttribute('material', 'color: red');
assert.shallowDeepEqual(el.getAttribute('material'), {shader: 'flat', color: 'red'});
assert.shallowDeepEqual(el.getAttribute('position'), {x: 1, y: 2, z: 3});
assert.shallowDeepEqual(el.getAttribute('rotation'), {x: 10, y: 20, z: 30});
assert.equal(el.mixinEls.length, 3);
});

test('clear mixin', function () {
var el = this.el;
mixinFactory('material', {material: 'shader: flat'});
Expand Down

0 comments on commit 1b9bea1

Please sign in to comment.