stackblitz/alien-signals

What is push-pull?

Closed this issue ยท 5 comments

Hey ๐Ÿ‘‹,

This is more a question than an issue.

In the readme, you say "I continued to research the Push-Pull reactivity system here" but does that mean? What is related to the "Push" in your current implementation? Do you think you could explain more?

medz commented

@Barbapapazes
I can't explain it to you in detail, because I don't fully understand the alien-signals source code yet.

However, my current understanding of the source code for alien-signals to implement Push-Pull reactivity system is as follows:

Push

  1. When the signal value is updated, look up the dependency through the subscriber list, and mark the dependency marked as needing to be propagated as needing to be checked for dirtiness

  2. At the end of the propagate function, if the batch depth is 0, run the effect notification

Pull

The most important thing is that Computed is lazy, so combined with Push, the rest is:

  1. Execute the queued effects

  2. At this time, the effect reads the value of computed

  3. computed is a lazy getter because it is marked in Push.2, and the prev value and current value are checked to decide whether to rebuild the value.

medz commented

@Barbapapazes See:

Thanks! This is very interresting!

I've seen a wiki that explains the related concepts in great detail, but I can't find it.

Here's another related one (I just learned that the push-pull-push method is the same algorithmic concept as Reactively!):
https://milomg.dev/2022-12-01/reactivity/

I've seen a wiki that explains the related concepts in great detail, but I can't find it.

I found it!

https://en.wikipedia.org/wiki/Reactive_programming

The concepts are explained very clearly in it and I think we can close this one. :)