Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single property schema array #5243

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ Component.prototype = {
return;
}

if (value instanceof Object && !(value instanceof window.HTMLElement)) {
if ((value instanceof Object) &&
!(value instanceof Array) &&
!(value instanceof window.HTMLElement)) {
// If value is an object, copy it to our pooled newAttrValue object to use to update
// the attrValue.
tempObject = this.objectPool.use();
Expand Down
32 changes: 32 additions & 0 deletions tests/core/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,42 @@ suite('Component', function () {
schema: {list: {default: ['a']}}
});
var component = new TestComponent(this.el);
assert.deepEqual(component.data.list, ['a']);
component.update = updateStub;
component.updateProperties({list: ['b']});
component.updateProperties({list: ['b']});
sinon.assert.calledOnce(updateStub);
assert.deepEqual(component.data.list, ['b']);
});

test('supports array property on entity creation', function (done) {
entityFactory();
registerComponent('dummy', {
schema: { list: {type: 'array', default: ['a']} }
});
var scene = document.querySelector('a-scene');
var el2 = document.createElement('a-entity');
el2.setAttribute('dummy', { list: ['b', 'c', 'd'] });
el2.addEventListener('componentinitialized', evt => {
assert.deepEqual(el2.components.dummy.data.list, ['b', 'c', 'd']);
done();
});
scene.appendChild(el2);
});

test('supports array property in single property schema on entity creation', function (done) {
entityFactory();
registerComponent('dummy', {
schema: {type: 'array', default: ['a']}
});
var scene = document.querySelector('a-scene');
var el2 = document.createElement('a-entity');
el2.setAttribute('dummy', ['b', 'c', 'd']);
el2.addEventListener('componentinitialized', () => {
assert.deepEqual(el2.components.dummy.data, ['b', 'c', 'd']);
done();
});
scene.appendChild(el2);
});

test('emit componentchanged when update calls setAttribute', function (done) {
Expand Down