Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/core/propertyTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function selectorParse (value) {
function selectorAllParse (value) {
if (!value) { return null; }
if (typeof value !== 'string') { return value; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should value also be wrapped in Array.from()? What is the use case? In case a NodeList instance is passed in?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to return [] in the cases above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first case may be for {default: ''} so we don't need to run that.

The second case is if an array or NodeList is passed in yeah.

return document.querySelectorAll(value);
return Array.from(document.querySelectorAll(value));
}

function selectorStringify (value) {
Expand All @@ -96,14 +96,10 @@ function selectorStringify (value) {
}

function selectorAllStringify (value) {
if (value.item) {
var els = '';
var i;
for (i = 0; i < value.length; ++i) {
els += '#' + value[i].getAttribute('id');
if (i !== value.length - 1) { els += ', '; }
}
return els;
if (value instanceof Array) {
return value.map(function (element) {
return '#' + element.getAttribute('id');
}).join(', ');
}
return defaultStringify(value);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/core/propertyTypes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ suite('propertyTypes', function () {
});

test('parses a set of valid selectors', function () {
assert.deepEqual(parse('#hello.itsme, #cool.itworks'), this.el.childNodes);
assert.deepEqual(parse('#hello.itsme, #cool.itworks'), Array.from(this.el.childNodes));
});

test('parses null selector', function () {
assert.deepEqual(parse('#goodbye'), this.el1.childNodes);
assert.deepEqual(parse('#goodbye'), Array.from(this.el1.childNodes));
});

test('stringifies valid selector', function () {
assert.equal(stringify(this.el.childNodes), '#hello, #cool');
assert.equal(stringify(Array.from(this.el.childNodes)), '#hello, #cool');
});
});

Expand Down