3 ms·
How do they intervene in the reactivity? Genuinely curious as I have implemented one such system in Go. Maybe I could improve in some stuff. I did use some ki
by aatd86 2y ago
How do they intervene in the reactivity?
Genuinely curious as I have implemented one such system in Go. Maybe I could improve in some stuff.
I did use some kind of weakreference substitute (using an integer map) but that was because I was lacking a feature (some kind of dependent type).
- mananaysiempre 2y agoI guess that wouldn’t be necessary if your dependency graph is static, but if dependencies can themselves change during change propagation, you do need weak references. Imagine input A affects node B affects output C. Then you probably want B to be collected if C becomes garbage. So the strong references need to go C→B→A. But the way a simple push strategy would actually proceed if A changes would be that A triggers a reevaluation of B, which then triggers a reevaluation of C. But A could be either immortal for semantic reasons (e.g. “the left mouse button was clicked” can’t really become garbage) or perhaps kept alive by some entirely unrelated dependent D. So A needs to be able to refer to B if it’s still alive but must not hold B alive, and similarly for the edge between B and C. The way to deal with this is to have store dependents in a weak set. (I don’t actually see how to implement one with plain weak references without finalizers.) Alternatively, just give up and say the dependency graph needs to be specified up front and only dies as a whole. My own dependency-graph/reactivity thing is not ready to see the light of day, so if you want some references I guess I can direct you to the author of the Sodium FRP library (not to be confused with the libsodium crypto library) and an FRP book mentioning[1] he implemented a cycle collector as a workaround for the lack of weak references in JavaScript (at the time). [1] https://web.archive.org/web/20240507181526/http://sodium.nz/t/sodium-internals-and-differences-between-language-implementations/464 https://web.archive.org/web/20240507181526/http://sodium.nz/...
- aatd86 2y agoOh ok I see why now. I eschewed this by using getters (the reference part of weakref is being used when one doesn't want to use explicit getters). Unlike reactish frameworks, I do not track dependencies but my reactive model is different and more fine-grained/lower-level. It's not needed.