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.Reactive and Vanx.List doesn't work with objects with Uint8Array (and some other objects too?) as children #344

Closed ash-hashtag closed 2 months ago

ash-hashtag commented 2 months ago

Reproduction

const {ul, li} = van.tags

const items = vanX.reactive([])

//van.add(document.body, vanX.list(ul, items, (l) => li(`${l.val.body}`)))
//van.add(document.body, vanX.list(ul, items, (l) => li(`${l.val.name}`)))
van.add(document.body, vanX.list(ul, items, (l) => li(new TextDecoder().decode(l.val.body))))

const encoder = new TextEncoder()
for (let i = 0; i < 10; i++) {
    items.push({ name: `${i}`, body: encoder.encode(i.toString()) })
}

jsfiddle of the exact thing above https://jsfiddle.net/xnrfgoe8/

the moment body is accessed, it throws exceptions.

Is it possible to not create the entire object with Proxy? like if we know object.body is not gonna change and the only use case is just inserting or deleting objects and represent them in ui, there is no reason for the children of the object to be reactive.

it may also be related to https://github.com/vanjs-org/van/issues/277#issue-2167462332

Tao-VanJS commented 2 months ago

You can use vanX.noreactive to wrap around objects that you don't want to convert into Proxy. I fixed the jsfiddle code you pasted with vanX.noreactive: https://jsfiddle.net/1srb5L6d/5/.

Let me know if it works for you :-)

ash-hashtag commented 2 months ago

Thank you, this is what I'm looking for, somehow I missed it.