vanjs-org / van

🍦 VanJS: World's smallest reactive UI framework. Incredibly Powerful, Insanely Small - Everyone can build a useful UI app in an hour.
https://vanjs.org
MIT License
3.77k stars 87 forks source link

vanX.list also looping empty values #241

Closed mintong89 closed 5 months ago

mintong89 commented 7 months ago

Is there any ways to let vanX.list only looping non-deleted values? For example if there are items deleted, the array value will show as:

console.log(apples)
>> [[Target]]: Array(4)
>> ...
>> Symbol(): (4) [empty × 2, 'apple', 'apple', ...]

Then when I want to create elements using vanX.list with using index key, it will show like this:

vanX.list(van.tags.ol, apples, (apple, deleter, index) => van.tags.li(index))
<ol>
 <li>2</li>
 <li>3</li>
</ol>

But what I want is

<ol>
 <li>0</li>
 <li>1</li>
</ol>

Is there any way to acheive it like adding filter(Boolean) on vanX.list?

Tao-VanJS commented 7 months ago

You can add this line:

vanX.replace(apples, items => items)

This will eliminate all the holes in your reactive array apples.

mintong89 commented 5 months ago

alright thanks for your solution!