sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.79k stars 148 forks source link

Example of mutating a collection #616

Closed andrewbaxter closed 12 months ago

andrewbaxter commented 1 year ago

All the examples/documentation related to iterables use static data. My guess is that you can't mutate a collection, you need to clone it, modify the clone, and replace the original.

seanpmyers commented 1 year ago

@andrewbaxter Hey is my discussion post related to what you're talking about? https://github.com/sycamore-rs/sycamore/discussions/615

andrewbaxter commented 1 year ago

I think your case is more complex, this was about modifying a simple list of values, rather than nesting (maybe?). But it is related... I wanted to store heavier objects too and I think in my original use case I wanted to nest things.

lukechu10 commented 12 months ago

Now that #626 has been merged, updating a Vec or other container inside a Signal is extremely simple. Simply use .update(|value| ...) where value is a mutable reference to the value inside the Signal. I think this can be closed now since the examples (in particular, todomvc and js-framework-benchmark) have both been updated to use this instead of cloning and pushing.