Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
4
karfau avatar

Can you please help me to understand why you are using runValAPI in line 12 instead of just accessing the val directly, like it done in updateThreadsafeStateEx? And why you are using api(were is that documented?) to run updateThreadsafeStateEx instead of calling it as a function? Thx

stevekrouse avatar

Great questions! I just added comments in the val to better explain my reasoning.

The background info you're missing is how we (1) bundle val references into vals and (2) save val state mutations in the database. The short answer is that we do these things before and after, respectively, the val runs. However if we want to have a proper update to state, we want to have the get and set happen during the val's execution, specifically while we have the lock acquired.

stevekrouse avatar

This whole system of val bundling and persisting is a bit too magical and confusing, which is why we are planning to move away from it in our v3 runtime: https://blog.val.town/blog/val-town-runtime-v3-my-mistakes-were-easy-the-solutions-simple

stevekrouse avatar

That blog posts discusses the future of imports, which will be a lot more explicit in the future. It doesn't discuss the future of mutation, but it'll also be explicit, with some sort of get and set interface, like a key value store

Updated: October 23, 2023