SolidOS / solid-ui

User Interface widgets and utilities for Solid
https://solidos.github.io/solid-ui/dist/solid-ui.js
MIT License
148 stars 41 forks source link

Incompatible use of `kb.any`? #243

Closed michielbdejong closed 4 years ago

michielbdejong commented 4 years ago

The call to kb.any in https://github.com/solid/solid-ui/blob/49165b4/src/widgets/forms.js#L75 will return a Term and so parts.elements will be undefined.

It looks like this code incorrectly assumes that kb.any will return a Collection?

michielbdejong commented 4 years ago

I was able to replace the failing code with a call to kb.each, but just to be sure, wanted to ask @megoth if he's aware of whether the return type of IndexedFormula#any has changed recently?

megoth commented 4 years ago

AFAIK IndexedFormula.each returns all triples that matches your query, while IndexedFormula.any will simply return the first match. It might be that the code was initially written with the naive assumption that the first match would always be a collection. Of course, with all things Linked Data, assumptions are dangerous and you should test them.

Another solution would be in line 77 to do if (parts && parts.elements) {.

michielbdejong commented 4 years ago

Ah I found the explanation, it was a bug in my RDF. https://solid.github.io/solid-ui/Documentation/forms-intro.html clearly says that (form, ns.ui('parts'), ?) should be Collection.

So I'll improve my example and also add the check you suggested so that the code outputs a useful warning if the RDF is incorrect.