Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Riot.js 2: Attribute with falsy value

I need to have an attribute which can have value of zero (0)

Riot template:

<my-tag time="{ time }">

this.time = condition ? '10' : '0'

</my-tag>

Desired result:

<my-tag time="0"></my-tag>

However, Riot automatically omits whole attribute if it has falsy value:

<my-tag></my-tag>

My current workaround:

this.on('updated', () => {
  $(this.root).attr('time', this.time)
})

In other words, i need time attribute to have exact value of time property.

Edit:

Looks like this has changed since 2.2.4.

Demo with Riot 2.2.4

this works as expected - both tags have rendered attribute time with according value

Demo with Riot 2.3.13

this fails - tag with attribute set to false has whole attribute removed

like image 771
Jozef Mikuláš Avatar asked Jan 13 '16 09:01

Jozef Mikuláš


1 Answers

This is working in riot v2.3.18:

<my-tag time="{ time ? '10' : '0'}">
    <script>
    this.time = false;
    </script>
</my-tag>

will generate

<my-tag time="0"></my-tag>
like image 178
peckles Avatar answered Nov 09 '22 08:11

peckles