Open delaneyj opened 1 year ago
EffectQueue.push(this);
to schedule a stabilize (i.e.
if (!stabilizeQueued) {
stabilizeQueued = true;
requestAnimationFrame(stabilize);
}
Reactive
primitive, but I didn't entirely succeed in abstracting away here. Passing in a function into the first argument makes it a computed or effect, and setting the effect flag will make it automatically run when dependencies change. Otherwise it is a memo, and lazily runs but efficiently caches. In other words, just wrap all reactive values and functions in reactive, and when the functions should be rerun, pass in effect=true
. (The reason this isn't the default is because sometimes you have many different outputs and you only want to sample one and not compute the others unless they are used)Update: we've added an API to do automatic stabilization: https://github.com/modderme123/reactively/blob/main/packages/core/src/core.ts#L324.
Just calling autoStabilize will automatically schedule microtasks which call stabilize
Ported your logic to a Go project that needs reactivity.
All test pass and the results are very promising. I ported benchmark as well. Used it with no threading to try to be as close to 1:1 with the current numbers.
On my machine
Port
My question is more of understanding some of the details
stale()
puts things in theEffectQueue
andstabilize()
takes them out. But I don't seestabilize()
called anyway in the repository.