javascript - RiotJS: How to cache values during loops? -


i'm looking improve performance , readability caching repeated values during each={} loops in riotjs. there way not render value and/or incur unnecessary performance overhead?

before:

<my-tag>   <p each="{item in data}">     <b if="{item.style == 'b'}">{item.text}</b>     <i if="{item.style == 'i'}">{item.text}</i>   </p>   data = [     {"text": "bold me", "style": "b"},     {"text": "italicize me", "style": "i"}   ]; </my-tag>  <!-- renders <p><b>bold me</b></p> <p><i>italicize me</i></p> --> 

after:

<my-tag>   <p each="{item in data}">     {style=item.style}     {text=item.text}     <b if="{style == 'b'}">{text}</b>     <i if="{style == 'i'}">{text}</i>   </p>   data = [     {"text": "bold me", "style": "b"},     {"text": "italicize me", "style": "i"}   ]; </my-tag>  <!-- renders <p>b bold me <b>bold me</b></p> <p>i italicize me <i>italicize me</i></p> --> 

jsfiddle

i think want :

<p each="{data}">   <b if="{style == 'b'}">{text}</b>   <i if="{style == 'i'}">{text}</i> </p> 

jsfiddle


Comments