Inconsistent tags behaviour with 1 item vs many #936

Closed
weepy opened this Issue Jul 8, 2015 · 3 comments

Projects

None yet

3 participants

@weepy
weepy commented Jul 8, 2015

I have an XY component

<xy>
<cursor each={ data in cursors } ></cursor>
</xy>

If I mount my tag with 1 item in an array:

riot.mount("xy", {
    cursors:  [{}]
})

then this.tags.cursor is a single cursor item

If I mount with cursor: [{}, {}] then this.tags.cursor in an array (expected behaviour)

Is this a bug or a feature ?

weepy

@rsbondi
Contributor
rsbondi commented Jul 8, 2015

This is the expected behavior. It is a trade off, easier if you use single instance to do this.tagname, and also meaningful for multiple tags that are not in a loop, but I can see where it is counter intuitive in a loop. So you would need to check if it is an array and handle accordingly.

@rsbondi rsbondi added the question label Jul 8, 2015
@weepy
weepy commented Jul 8, 2015

Perhaps this is part of the implementation, but it seems easy to reason that it should be an array if it was declared via "each" ?

@GianlucaGuarini GianlucaGuarini added this to the 3.0.0 milestone Feb 14, 2016
@GianlucaGuarini
Member

This issue is fixed in riot@3.0.0 http://plnkr.co/edit/Uyr2Do4976uGKLLzAgtm?p=preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment