Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

State management seems a bit counter intuitive at a glance.

I found this statement to be confusing; https://vanjs.org/tutorial#state-val-is-immutable While you can update State objects by setting the val property, you should never mutate the underlying object of val itself.

Then beneath is an example of the following;

   const text = van.state("VanJS")
   ...
   input({type: "text", value: text, oninput: e => text.val = e.target.value})

Which looks like a mutation - after reading a bit more around it is clearer that .val has a setter; but at a glance it just isn't obvious what is happening which I feel isn't intuitive.


States are mutable whose value can be get/set via the ".val" property. However, the value of the states should be (ideally) an immutable object (or primitives).


Yeah I understood that better, thanks.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: